InterventionImageProcessor   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 2
dl 0
loc 56
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setConfig() 0 4 1
A create() 0 7 1
A load() 0 7 1
A save() 0 4 1
A insert() 0 4 1
A getWidth() 0 8 2
A getHeight() 0 8 2
1
<?php
2
3
namespace CSSPrites\ImageProcessor;
4
5
use Intervention\Image\ImageManager;
6
7
/**
8
 * @codeCoverageIgnore
9
 */
10
class InterventionImageProcessor extends AbstractImageProcessor implements ImageProcessorInterface
11
{
12
    public function __construct()
13
    {
14
        $this->manager = new ImageManager();
15
    }
16
17
    public function setConfig($config)
18
    {
19
        $this->manager->configure($config);
20
    }
21
22
    public function create($width, $height, $background = null)
23
    {
24
        $newImage = new self();
25
        $newImage->setImage($this->manager->canvas($width, $height, $background));
26
27
        return $newImage;
28
    }
29
30
    public function load($path)
31
    {
32
        $newImage = new self();
33
        $newImage->setImage($this->manager->make($path));
34
35
        return $newImage;
36
    }
37
38
    public function save($path)
39
    {
40
        return $this->image->save($path);
41
    }
42
43
    public function insert(ImageProcessorInterface $image, $x = 0, $y = 0)
44
    {
45
        return $this->image->insert($image->getImage(), 'top-left', $x, $y);
46
    }
47
48
    public function getWidth()
49
    {
50
        if (is_null($this->image)) {
51
            throw new \Exception('No image created / loaded');
52
        }
53
54
        return $this->image->width();
55
    }
56
57
    public function getHeight()
58
    {
59
        if (is_null($this->image)) {
60
            throw new \Exception('No image created / loaded');
61
        }
62
63
        return $this->image->height();
64
    }
65
}
66