|
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
|
|
|
|