Completed
Push — master ( 2076b7...2510e5 )
by Afshin
02:23
created

ImageService   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 69
rs 10
c 0
b 0
f 0
wmc 12

5 Methods

Rating   Name   Duplication   Size   Complexity  
A scaleResize() 0 9 1
A resize() 0 9 1
A cropResize() 0 9 1
C createPhotos() 0 24 8
A zoomCrop() 0 7 1
1
<?php
2
namespace Core\Services;
3
4
use Gregwar\Image\Image as GImage;
0 ignored issues
show
Bug introduced by
The type Gregwar\Image\Image was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
5
use Core\Interfaces\_Service;
6
7
class ImageService extends _Service
8
{
9
10
    public function cropResize($src,$destUrl, $width, $height, $quality = 80,$fileExt  = 'jpg')
11
    {
12
        $image = GImage::open($src);
13
        $image->cropResize($width, $height);
14
        $destUrl = $destUrl.'.'.$fileExt;
15
        $image->save($destUrl, $fileExt = 'jpg', $quality );
16
        
17
18
        return $image;
19
    }
20
21
    public function scaleResize($src,$destUrl, $width, $height, $quality = 80,$fileExt  = 'jpg')
22
    {
23
        $image = GImage::open($src);
24
        $image->scaleResize($width, $height);
25
        $destUrl = $destUrl.'.'.$fileExt;
26
        $image->save($destUrl, $fileExt = 'jpg', $quality );
27
28
29
        return $image;
30
    }
31
32
    public function resize($src,$destUrl, $width, $height, $quality = 80,$fileExt  = 'jpg')
33
    {
34
        $image = GImage::open($src);
35
        $image->resize($width, $height);
36
        $destUrl = $destUrl.'.'.$fileExt;
37
        $image->save($destUrl, $fileExt = 'jpg', $quality );
38
39
40
        return $image;
41
    }
42
43
    public function zoomCrop($src,$destUrl, $width, $height, $quality = 80,$fileExt  = 'jpg')
44
    {
45
        $image = GImage::open($src);
46
        $image->zoomCrop($width, $height);
47
        $destUrl = $destUrl.'.'.$fileExt;
48
        $image->save($destUrl, $fileExt = 'jpg', $quality );
49
        return $image;
50
    }
51
52
    public function createPhotos($src,$photoid,$type='user_photo', $dimensions = false)
53
    {
54
        // Get default dimensions
55
        $dest = realpath('.'.$GLOBALS['container']['image']['upload_path']);
56
57
58
        $defaultDimensions = $dimensions ? $dimensions : $GLOBALS['container']['image'][$type]['dimensions'];
59
        foreach ($defaultDimensions as $keys=>$dimension)
60
        {
61
            if(!isset($dimension[2])) $dimension[2] = 100; // quality
62
            if(!isset($dimension[4])) $dimension[4] = 'jpg'; // quality
63
64
            $destUrl = $dest.'/'.getImageDirName($photoid,$type).getImageFileName($photoid,$keys,$type);
65
66
            if(isset($dimension[3]) && $dimension[3] == true){
67
                $image = $this->zoomCrop($src,trim($destUrl),$dimension[0], $dimension[1], $dimension[2],$dimension[4]);
68
            }else {
69
                $image = $this->cropResize($src,trim($destUrl),$dimension[0], $dimension[1], $dimension[2],$dimension[4]);
70
            }
71
            
72
            // $image = $this->cropResize($src,trim($destUrl),$dimension[0], $dimension[1], $dimension[2],$dimension[4]);
73
74
            if($image ){
75
                $cropedArr[$keys] = $src;
76
            }
77
        }
78
    }
79
80
81
82
}