1
|
|
|
<?php |
2
|
|
|
namespace HtImgModule\View\Model; |
3
|
|
|
|
4
|
|
|
use Zend\View\Model\ViewModel; |
5
|
|
|
use Imagine\Image\ImageInterface; |
6
|
|
|
use HtImgModule\Exception; |
7
|
|
|
|
8
|
|
|
class ImageModel extends ViewModel |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Image won't need to be captured into a |
12
|
|
|
* a parent container by default. |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $captureTo = null; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Image is terminal |
20
|
|
|
* |
21
|
|
|
* @var bool |
22
|
|
|
*/ |
23
|
|
|
protected $terminate = true; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Path of image to show |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $imagePath; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var ImageInterface |
34
|
|
|
*/ |
35
|
|
|
protected $image; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $format = 'png'; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var array |
44
|
|
|
*/ |
45
|
|
|
protected $imageOutputOptions = []; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Constructor |
49
|
|
|
* |
50
|
|
|
* @param ImageInterface|string $imageOrPath |
51
|
|
|
* @param string|null $format |
52
|
|
|
* @param array $imageOutputOptions |
53
|
|
|
* @throws Exception\InvalidArgumentException |
54
|
|
|
*/ |
55
|
6 |
|
public function __construct($imageOrPath = null, $format = null, array $imageOutputOptions = []) |
56
|
|
|
{ |
57
|
6 |
|
if ($imageOrPath !== null) { |
58
|
4 |
|
if (is_string($imageOrPath)) { |
59
|
1 |
|
$this->setImagePath($imageOrPath); |
60
|
4 |
|
} elseif ($imageOrPath instanceof ImageInterface) { |
61
|
3 |
|
$this->setImage($imageOrPath); |
62
|
|
|
} else { |
63
|
1 |
|
throw new Exception\InvalidArgumentException( |
64
|
1 |
|
sprintf( |
65
|
1 |
|
'%s expects parameter 1 to be image path or instance of Imagine\Image\ImageInterface, %s provided instead', |
66
|
1 |
|
__METHOD__, |
67
|
1 |
|
is_object($imageOrPath) ? get_class($imageOrPath) : gettype($imageOrPath) |
68
|
|
|
) |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
} |
72
|
5 |
|
if ($format !== null) { |
73
|
3 |
|
$this->setFormat($format); |
74
|
|
|
} |
75
|
5 |
|
$this->setImageOutputOptions($imageOutputOptions); |
76
|
5 |
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Sets path of image to show |
80
|
|
|
* |
81
|
|
|
* @param string $imagePath |
82
|
|
|
* @return self |
83
|
|
|
*/ |
84
|
1 |
|
public function setImagePath($imagePath) |
85
|
|
|
{ |
86
|
1 |
|
$this->imagePath = $imagePath; |
87
|
|
|
|
88
|
1 |
|
return $this; |
89
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Gets path of image to show |
94
|
|
|
* |
95
|
|
|
* @return string $fileName |
96
|
|
|
*/ |
97
|
2 |
|
public function getImagePath() |
98
|
|
|
{ |
99
|
2 |
|
return $this->imagePath; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Sets image |
104
|
|
|
* |
105
|
|
|
* @param ImageInterface $image |
106
|
|
|
* @return self |
107
|
|
|
*/ |
108
|
3 |
|
public function setImage(ImageInterface $image) |
109
|
|
|
{ |
110
|
3 |
|
$this->image = $image; |
111
|
|
|
|
112
|
3 |
|
return $this; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Gets image |
117
|
|
|
* |
118
|
|
|
* @return ImageInterface |
119
|
|
|
*/ |
120
|
4 |
|
public function getImage() |
121
|
|
|
{ |
122
|
4 |
|
return $this->image; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Sets format |
127
|
|
|
* |
128
|
|
|
* @param string $format |
129
|
|
|
* @return self |
130
|
|
|
*/ |
131
|
3 |
|
public function setFormat($format) |
132
|
|
|
{ |
133
|
3 |
|
$this->format = $format; |
134
|
|
|
|
135
|
3 |
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Gets format |
140
|
|
|
* |
141
|
|
|
* @return string |
142
|
|
|
*/ |
143
|
3 |
|
public function getFormat() |
144
|
|
|
{ |
145
|
3 |
|
return $this->format; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Sets imageOutputOptions |
150
|
|
|
* |
151
|
|
|
* @param array $imageOutputOptions |
152
|
|
|
* @return self |
153
|
|
|
*/ |
154
|
5 |
|
public function setImageOutputOptions(array $imageOutputOptions) |
155
|
|
|
{ |
156
|
5 |
|
$this->imageOutputOptions = $imageOutputOptions; |
157
|
|
|
|
158
|
5 |
|
return $this; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Gets imageOutputOptions |
163
|
|
|
* |
164
|
|
|
* @return array |
165
|
|
|
*/ |
166
|
2 |
|
public function getImageOutputOptions() |
167
|
|
|
{ |
168
|
2 |
|
return $this->imageOutputOptions; |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
|