1 | <?php |
||
14 | class FastImageSize |
||
15 | { |
||
16 | /** @var StreamReader */ |
||
17 | protected $streamReader; |
||
18 | |||
19 | /** @var array Size info that is returned */ |
||
20 | protected $size = array(); |
||
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 | 76 | public function __construct() |
|
94 | |||
95 | /** |
||
96 | * Get size array |
||
97 | * |
||
98 | * @return array|bool Size array if size could be evaluated, false if not |
||
99 | */ |
||
100 | 75 | protected function getSize() |
|
104 | |||
105 | /** |
||
106 | * Get image dimensions of supplied image |
||
107 | * |
||
108 | * @param string $file Path to image that should be checked |
||
109 | * @param string $type Mimetype of image |
||
110 | * @return array|bool Array with image dimensions if successful, false if not |
||
111 | */ |
||
112 | 75 | public function getImageSize($file, $type = '') |
|
131 | |||
132 | /** |
||
133 | * Get dimensions of image if type is unknown |
||
134 | * |
||
135 | * @param string $filename Path to file |
||
136 | */ |
||
137 | 20 | protected function getImagesizeUnknownType($filename) |
|
155 | |||
156 | /** |
||
157 | * Get image size by file extension |
||
158 | * |
||
159 | * @param string $file Path to image that should be checked |
||
160 | * @param string $extension Extension/type of image |
||
161 | */ |
||
162 | 55 | protected function getImageSizeByExtension($file, $extension) |
|
169 | |||
170 | /** |
||
171 | * Reset values to default |
||
172 | */ |
||
173 | 75 | protected function resetValues() |
|
178 | |||
179 | /** |
||
180 | * Set mime type based on supplied image |
||
181 | * |
||
182 | * @param int $type Type of image |
||
183 | */ |
||
184 | 48 | public function setImageType($type) |
|
188 | |||
189 | /** |
||
190 | * Set size info |
||
191 | * |
||
192 | * @param array $size Array containing size info for image |
||
193 | */ |
||
194 | 54 | public function setSize($size) |
|
198 | } |
||
199 |