1 | <?php |
||
14 | class FastImageSize |
||
15 | { |
||
16 | /** @var array Size info that is returned */ |
||
17 | protected $size = array(); |
||
18 | |||
19 | /** @var string Data retrieved from remote */ |
||
20 | protected $data = ''; |
||
21 | |||
22 | /** @var array List of supported image types and associated image types */ |
||
23 | protected $supportedTypes = array( |
||
24 | 'png' => array('png'), |
||
25 | 'gif' => array('gif'), |
||
26 | 'jpeg' => array( |
||
27 | 'jpeg', |
||
28 | 'jpg', |
||
29 | 'jpe', |
||
30 | 'jif', |
||
31 | 'jfif', |
||
32 | 'jfi', |
||
33 | ), |
||
34 | 'jp2' => array( |
||
35 | 'jp2', |
||
36 | 'j2k', |
||
37 | 'jpf', |
||
38 | 'jpg2', |
||
39 | 'jpx', |
||
40 | 'jpm', |
||
41 | ), |
||
42 | 'psd' => array( |
||
43 | 'psd', |
||
44 | 'photoshop', |
||
45 | ), |
||
46 | 'bmp' => array('bmp'), |
||
47 | 'tif' => array( |
||
48 | 'tif', |
||
49 | 'tiff', |
||
50 | ), |
||
51 | 'wbmp' => array( |
||
52 | 'wbm', |
||
53 | 'wbmp', |
||
54 | 'vnd.wap.wbmp', |
||
55 | ), |
||
56 | 'iff' => array( |
||
57 | 'iff', |
||
58 | 'x-iff', |
||
59 | ), |
||
60 | 'ico' => array( |
||
61 | 'ico', |
||
62 | 'vnd.microsoft.icon', |
||
63 | 'x-icon', |
||
64 | 'icon', |
||
65 | ), |
||
66 | 'webp' => array( |
||
67 | 'webp', |
||
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 | * Get image dimensions of supplied image |
||
79 | * |
||
80 | * @param string $file Path to image that should be checked |
||
81 | * @param string $type Mimetype of image |
||
82 | * @return array|bool Array with image dimensions if successful, false if not |
||
83 | */ |
||
84 | 88 | public function getImageSize($file, $type = '') |
|
103 | |||
104 | /** |
||
105 | * Get dimensions of image if type is unknown |
||
106 | * |
||
107 | * @param string $filename Path to file |
||
108 | */ |
||
109 | 17 | protected function getImagesizeUnknownType($filename) |
|
128 | |||
129 | /** |
||
130 | * Get image size by file extension |
||
131 | * |
||
132 | * @param string $file Path to image that should be checked |
||
133 | * @param string $extension Extension/type of image |
||
134 | */ |
||
135 | 71 | protected function getImageSizeByExtension($file, $extension) |
|
144 | |||
145 | /** |
||
146 | * Reset values to default |
||
147 | */ |
||
148 | 88 | protected function resetValues() |
|
153 | |||
154 | /** |
||
155 | * Set mime type based on supplied image |
||
156 | * |
||
157 | * @param int $type Type of image |
||
158 | */ |
||
159 | 56 | public function setImageType($type) |
|
163 | |||
164 | /** |
||
165 | * Set size info |
||
166 | * |
||
167 | * @param array $size Array containing size info for image |
||
168 | */ |
||
169 | 63 | public function setSize($size) |
|
173 | |||
174 | /** |
||
175 | * Get image from specified path/source |
||
176 | * |
||
177 | * @param string $filename Path to image |
||
178 | * @param int $offset Offset at which reading of the image should start |
||
179 | * @param int $length Maximum length that should be read |
||
180 | * @param bool $forceLength True if the length needs to be the specified |
||
181 | * length, false if not. Default: true |
||
182 | * |
||
183 | * @return false|string Image data or false if result was empty |
||
184 | */ |
||
185 | 87 | public function getImage($filename, $offset, $length, $forceLength = true) |
|
201 | |||
202 | /** |
||
203 | * Get return data |
||
204 | * |
||
205 | * @return array|bool Size array if dimensions could be found, false if not |
||
206 | */ |
||
207 | protected function getReturnData() |
||
211 | |||
212 | /** |
||
213 | * Load all supported types |
||
214 | */ |
||
215 | 16 | protected function loadAllTypes() |
|
222 | |||
223 | /** |
||
224 | * Load an image type by extension |
||
225 | * |
||
226 | * @param string $extension Extension of image |
||
227 | */ |
||
228 | 71 | protected function loadExtension($extension) |
|
242 | |||
243 | /** |
||
244 | * Load an image type |
||
245 | * |
||
246 | * @param string $imageType Mimetype |
||
247 | */ |
||
248 | 86 | protected function loadType($imageType) |
|
265 | } |
||
266 |