InterventionImageProcessor::save()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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