1 | <?php |
||
13 | class Image |
||
14 | { |
||
15 | /** |
||
16 | * File source |
||
17 | * @var string |
||
18 | */ |
||
19 | public $source; |
||
20 | |||
21 | /** |
||
22 | * Informations about the image |
||
23 | * @var array |
||
24 | */ |
||
25 | protected $info; |
||
26 | |||
27 | /** |
||
28 | * Image resource |
||
29 | * @var \Intervention\Image\Image |
||
30 | */ |
||
31 | protected $image; |
||
32 | |||
33 | /** |
||
34 | * Create an image and get informations about it |
||
35 | * |
||
36 | * @param string $source |
||
37 | * |
||
38 | * @throws \Exception if cannot find or load the file |
||
39 | */ |
||
40 | public function __construct($source) |
||
50 | |||
51 | /** |
||
52 | 102 | * @return \Intervention\Image\Image |
|
53 | 102 | */ |
|
54 | 96 | public function getImage() |
|
58 | |||
59 | 18 | /** |
|
60 | * @param \Intervention\Image\Image $image |
||
61 | 18 | * used mainly for unit tests, we cannot typehint as we get a mockery object |
|
62 | */ |
||
63 | public function setImage($image) |
||
67 | |||
68 | 18 | /** |
|
69 | * File's width |
||
70 | 18 | * |
|
71 | 18 | * @return int |
|
72 | */ |
||
73 | public function getWidth() |
||
77 | |||
78 | /** |
||
79 | * File's height |
||
80 | * |
||
81 | * @return int |
||
82 | */ |
||
83 | public function getHeight() |
||
87 | |||
88 | /** |
||
89 | * File's size |
||
90 | * |
||
91 | * @return int |
||
92 | */ |
||
93 | public function getFileSize() |
||
97 | |||
98 | /** |
||
99 | 51 | * Get details about an image. |
|
100 | * |
||
101 | 51 | * @return bool|array false, if the file could not be found or is not an image. Otherwise, a keyed array containing information about the image: |
|
102 | * - "width": Width, in pixels. |
||
103 | * - "height": Height, in pixels. |
||
104 | * - "file_size": File size in bytes. |
||
105 | */ |
||
106 | public function getInfo() |
||
116 | |||
117 | /** |
||
118 | * Scales an image to the exact width and height given. |
||
119 | 6 | * |
|
120 | * This function achieves the target aspect ratio by cropping the original image |
||
121 | 6 | * equally on both sides, or equally on the top and bottom. This function is |
|
122 | * useful to create uniform sized avatars from larger images. |
||
123 | * |
||
124 | * The resulting image always has the exact target dimensions. |
||
125 | * |
||
126 | * @param int $width The target width, in pixels. |
||
127 | * @param int $height The target height, in pixels. |
||
128 | * |
||
129 | * @throws \LogicException if the parameters are wrong |
||
130 | * |
||
131 | * @see resize() |
||
132 | 3 | * @see crop() |
|
133 | */ |
||
134 | 3 | public function scale_and_crop($width, $height) |
|
153 | |||
154 | /** |
||
155 | * Scales an image to the given width and height while maintaining aspect ratio. |
||
156 | * |
||
157 | * The resulting image can be smaller for one or both target dimensions. |
||
158 | * |
||
159 | * @param int $width |
||
160 | * The target width, in pixels. This value is omitted then the scaling will |
||
161 | * based only on the height value. |
||
162 | * @param int $height |
||
163 | * The target height, in pixels. This value is omitted then the scaling will |
||
164 | 33 | * based only on the width value. |
|
165 | */ |
||
166 | 33 | public function scale($width = null, $height = null) |
|
184 | |||
185 | /** |
||
186 | * Resize an image to the given dimensions (ignoring aspect ratio). |
||
187 | * |
||
188 | * @param int $width The target width, in pixels. |
||
189 | * @param int $height The target height, in pixels. |
||
190 | */ |
||
191 | public function resize($width, $height) |
||
195 | |||
196 | /** |
||
197 | * Rotate an image by the given number of degrees. |
||
198 | 15 | * |
|
199 | * @param int $degrees The number of (clockwise) degrees to rotate the image. |
||
200 | 15 | * @param string|null $background hexadecimal background color |
|
201 | 3 | * @param bool $random |
|
202 | */ |
||
203 | public function rotate($degrees, $background = null, $random = false) |
||
218 | |||
219 | /** |
||
220 | * Crop an image to the rectangle specified by the given rectangle. |
||
221 | * |
||
222 | 36 | * @param int $xoffset |
|
223 | * The top left coordinate, in pixels, of the crop area (x axis value). |
||
224 | 36 | * @param int $yoffset |
|
225 | 36 | * The top left coordinate, in pixels, of the crop area (y axis value). |
|
226 | * @param int $width |
||
227 | * The target width, in pixels. |
||
228 | * @param int $height |
||
229 | * The target height, in pixels. |
||
230 | * |
||
231 | * @throws \LogicException if the parameters are wrong |
||
232 | */ |
||
233 | public function crop($xoffset, $yoffset, $width, $height) |
||
253 | |||
254 | /** |
||
255 | * Convert an image to grayscale. |
||
256 | */ |
||
257 | public function desaturate() |
||
261 | |||
262 | /** |
||
263 | * Close the image and save the changes to a file. |
||
264 | * |
||
265 | * @param string|null $destination Destination path where the image should be saved. If it is empty the original image file will be overwritten. |
||
266 | * @throws \RuntimeException |
||
267 | * @return Image image or false, based on success. |
||
268 | 48 | */ |
|
269 | public function save($destination = null) |
||
284 | } |
||
285 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: