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 | ); |
||
67 | |||
68 | /** @var array Class map that links image extensions/mime types to class */ |
||
69 | protected $classMap; |
||
70 | |||
71 | /** @var array An array containing the classes of supported image types */ |
||
72 | protected $type; |
||
73 | |||
74 | /** |
||
75 | * Constructor for fastImageSize class |
||
76 | */ |
||
77 | 57 | public function __construct() |
|
92 | |||
93 | /** |
||
94 | * Get image dimensions of supplied image |
||
95 | * |
||
96 | * @param string $file Path to image that should be checked |
||
97 | * @param string $type Mimetype of image |
||
98 | * @return array|bool Array with image dimensions if successful, false if not |
||
99 | */ |
||
100 | 57 | public function getImageSize($file, $type = '') |
|
119 | |||
120 | /** |
||
121 | * Get dimensions of image if type is unknown |
||
122 | * |
||
123 | * @param string $filename Path to file |
||
124 | */ |
||
125 | 15 | protected function getImagesizeUnknownType($filename) |
|
143 | |||
144 | /** |
||
145 | * Get image size by file extension |
||
146 | * |
||
147 | * @param string $file Path to image that should be checked |
||
148 | * @param string $extension Extension/type of image |
||
149 | */ |
||
150 | 42 | protected function getImageSizeByExtension($file, $extension) |
|
157 | |||
158 | /** |
||
159 | * Reset values to default |
||
160 | */ |
||
161 | 57 | protected function resetValues() |
|
166 | |||
167 | /** |
||
168 | * Set mime type based on supplied image |
||
169 | * |
||
170 | * @param int $type Type of image |
||
171 | */ |
||
172 | 33 | public function setImageType($type) |
|
176 | |||
177 | /** |
||
178 | * Set size info |
||
179 | * |
||
180 | * @param array $size Array containing size info for image |
||
181 | */ |
||
182 | 39 | public function setSize($size) |
|
186 | |||
187 | /** |
||
188 | * Get image from specified path/source |
||
189 | * |
||
190 | * @param string $filename Path to image |
||
191 | * @param int $offset Offset at which reading of the image should start |
||
192 | * @param int $length Maximum length that should be read |
||
193 | * @param bool $forceLength True if the length needs to be the specified |
||
194 | * length, false if not. Default: true |
||
195 | * |
||
196 | * @return false|string Image data or false if result was empty |
||
197 | */ |
||
198 | 56 | public function getImage($filename, $offset, $length, $forceLength = true) |
|
231 | |||
232 | /** |
||
233 | * Get return data |
||
234 | * |
||
235 | * @return array|bool Size array if dimensions could be found, false if not |
||
236 | */ |
||
237 | protected function getReturnData() |
||
241 | } |
||
242 |