1 | <?php |
||
14 | class FastImageSize |
||
15 | { |
||
16 | /** @var bool Flag whether allow_url_fopen is enabled */ |
||
17 | protected $isFopenEnabled = false; |
||
18 | |||
19 | /** @var array Size info that is returned */ |
||
20 | protected $size = array(); |
||
21 | |||
22 | /** @var string Data retrieved from remote */ |
||
23 | protected $data = ''; |
||
24 | |||
25 | /** @var array List of supported image types and associated image types */ |
||
26 | protected $supportedTypes = array( |
||
27 | 'png' => array('png'), |
||
28 | 'gif' => array('gif'), |
||
29 | 'jpeg' => array( |
||
30 | 'jpeg', |
||
31 | 'jpg', |
||
32 | 'jpe', |
||
33 | 'jif', |
||
34 | 'jfif', |
||
35 | 'jfi', |
||
36 | ), |
||
37 | 'jp2' => array( |
||
38 | 'jp2', |
||
39 | 'j2k', |
||
40 | 'jpf', |
||
41 | 'jpg2', |
||
42 | 'jpx', |
||
43 | 'jpm', |
||
44 | ), |
||
45 | 'psd' => array( |
||
46 | 'psd', |
||
47 | 'photoshop', |
||
48 | ), |
||
49 | 'bmp' => array('bmp'), |
||
50 | 'tif' => array( |
||
51 | 'tif', |
||
52 | 'tiff', |
||
53 | ), |
||
54 | 'wbmp' => array( |
||
55 | 'wbm', |
||
56 | 'wbmp', |
||
57 | 'vnd.wap.wbmp', |
||
58 | ), |
||
59 | 'iff' => array( |
||
60 | 'iff', |
||
61 | 'x-iff', |
||
62 | ), |
||
63 | 'ico' => array( |
||
64 | 'ico', |
||
65 | 'vnd.microsoft.icon', |
||
66 | 'x-icon', |
||
67 | 'icon', |
||
68 | ), |
||
69 | ); |
||
70 | |||
71 | /** @var array Class map that links image extensions/mime types to class */ |
||
72 | protected $classMap; |
||
73 | |||
74 | /** @var array An array containing the classes of supported image types */ |
||
75 | protected $type; |
||
76 | |||
77 | /** |
||
78 | * Constructor for fastImageSize class |
||
79 | */ |
||
80 | 72 | public function __construct() |
|
98 | |||
99 | /** |
||
100 | * Get size array |
||
101 | * |
||
102 | * @return array|bool Size array if size could be evaluated, false if not |
||
103 | */ |
||
104 | 72 | protected function getSize() |
|
108 | |||
109 | /** |
||
110 | * Get image dimensions of supplied image |
||
111 | * |
||
112 | * @param string $file Path to image that should be checked |
||
113 | * @param string $type Mimetype of image |
||
114 | * @return array|bool Array with image dimensions if successful, false if not |
||
115 | */ |
||
116 | 72 | public function getImageSize($file, $type = '') |
|
135 | |||
136 | /** |
||
137 | * Get dimensions of image if type is unknown |
||
138 | * |
||
139 | * @param string $filename Path to file |
||
140 | */ |
||
141 | 18 | protected function getImagesizeUnknownType($filename) |
|
159 | |||
160 | /** |
||
161 | * Get image size by file extension |
||
162 | * |
||
163 | * @param string $file Path to image that should be checked |
||
164 | * @param string $extension Extension/type of image |
||
165 | */ |
||
166 | 54 | protected function getImageSizeByExtension($file, $extension) |
|
173 | |||
174 | /** |
||
175 | * Reset values to default |
||
176 | */ |
||
177 | 72 | protected function resetValues() |
|
182 | |||
183 | /** |
||
184 | * Set mime type based on supplied image |
||
185 | * |
||
186 | * @param int $type Type of image |
||
187 | */ |
||
188 | 47 | public function setImageType($type) |
|
192 | |||
193 | /** |
||
194 | * Set size info |
||
195 | * |
||
196 | * @param array $size Array containing size info for image |
||
197 | */ |
||
198 | 53 | public function setSize($size) |
|
202 | |||
203 | /** |
||
204 | * Get image from specified path/source |
||
205 | * |
||
206 | * @param string $filename Path to image |
||
207 | * @param int $offset Offset at which reading of the image should start |
||
208 | * @param int $length Maximum length that should be read |
||
209 | * @param bool $forceLength True if the length needs to be the specified |
||
210 | * length, false if not. Default: true |
||
211 | * |
||
212 | * @return false|string Image data or false if result was empty |
||
213 | */ |
||
214 | 69 | public function getImage($filename, $offset, $length, $forceLength = true) |
|
230 | |||
231 | /** |
||
232 | * Get return data |
||
233 | * |
||
234 | * @return array|bool Size array if dimensions could be found, false if not |
||
235 | */ |
||
236 | protected function getReturnData() |
||
240 | |||
241 | /** |
||
242 | * Get image data for specified filename with offset and length |
||
243 | * |
||
244 | * @param string $filename Path to image |
||
245 | * @param int $offset Offset at which reading of the image should start |
||
246 | * @param int $length Maximum length that should be read |
||
247 | */ |
||
248 | 69 | protected function getImageData($filename, $offset, $length) |
|
279 | |||
280 | /** |
||
281 | * Get seekable image data in form of Guzzle stream interface |
||
282 | * |
||
283 | * @param string $filename Filename / URL to get |
||
284 | * @param int $offset Offset for response body |
||
285 | * @return \GuzzleHttp\Stream\StreamInterface|null Stream interface of |
||
286 | * requested image or null if it could not be retrieved |
||
287 | */ |
||
288 | 27 | public function getSeekableImageData($filename, $offset) |
|
303 | } |
||
304 |