blob: aee4f5fce82ee6f9597fbd53620c8bc9ff902893 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
<?php
namespace League\Glide\Api;
use Intervention\Image\ImageManager;
use InvalidArgumentException;
use League\Glide\Manipulators\ManipulatorInterface;
class Api implements ApiInterface
{
/**
* Intervention image manager.
* @var ImageManager
*/
protected $imageManager;
/**
* Collection of manipulators.
* @var array
*/
protected $manipulators;
/**
* Create API instance.
* @param ImageManager $imageManager Intervention image manager.
* @param array $manipulators Collection of manipulators.
*/
public function __construct(ImageManager $imageManager, array $manipulators)
{
$this->setImageManager($imageManager);
$this->setManipulators($manipulators);
}
/**
* Set the image manager.
* @param ImageManager $imageManager Intervention image manager.
*/
public function setImageManager(ImageManager $imageManager)
{
$this->imageManager = $imageManager;
}
/**
* Get the image manager.
* @return ImageManager Intervention image manager.
*/
public function getImageManager()
{
return $this->imageManager;
}
/**
* Set the manipulators.
* @param array $manipulators Collection of manipulators.
*/
public function setManipulators(array $manipulators)
{
foreach ($manipulators as $manipulator) {
if (!($manipulator instanceof ManipulatorInterface)) {
throw new InvalidArgumentException('Not a valid manipulator.');
}
}
$this->manipulators = $manipulators;
}
/**
* Get the manipulators.
* @return array Collection of manipulators.
*/
public function getManipulators()
{
return $this->manipulators;
}
/**
* Perform image manipulations.
* @param string $source Source image binary data.
* @param array $params The manipulation params.
* @return string Manipulated image binary data.
*/
public function run($source, array $params)
{
$image = $this->imageManager->make($source);
foreach ($this->manipulators as $manipulator) {
$manipulator->setParams($params);
$image = $manipulator->run($image);
}
return $image->getEncoded();
}
}
|