Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
FastImageSize.php
001 <?php
002
003 /**
004 * fast-image-size base class
005 * @package fast-image-size
006 * @copyright (c) Marc Alexander <admin@m-a-styles.de>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace FastImageSize;
013
014 class FastImageSize
015 {
016 /** @var array Size info that is returned */
017 protected $size = array();
018
019 /** @var string Data retrieved from remote */
020 protected $data = '';
021
022 /** @var array List of supported image types and associated image types */
023 protected $supportedTypes = array(
024 'png' => array('png'),
025 'gif' => array('gif'),
026 'jpeg' => array(
027 'jpeg',
028 'jpg',
029 'jpe',
030 'jif',
031 'jfif',
032 'jfi',
033 ),
034 'jp2' => array(
035 'jp2',
036 'j2k',
037 'jpf',
038 'jpg2',
039 'jpx',
040 'jpm',
041 ),
042 'psd' => array(
043 'psd',
044 'photoshop',
045 ),
046 'bmp' => array('bmp'),
047 'tif' => array(
048 'tif',
049 'tiff',
050 ),
051 'wbmp' => array(
052 'wbm',
053 'wbmp',
054 'vnd.wap.wbmp',
055 ),
056 'iff' => array(
057 'iff',
058 'x-iff',
059 ),
060 'ico' => array(
061 'ico',
062 'vnd.microsoft.icon',
063 'x-icon',
064 'icon',
065 ),
066 'webp' => array(
067 'webp',
068 )
069 );
070
071 /** @var array Class map that links image extensions/mime types to class */
072 protected $classMap;
073
074 /** @var array An array containing the classes of supported image types */
075 protected $type;
076
077 /**
078 * Get image dimensions of supplied image
079 *
080 * @param string $file Path to image that should be checked
081 * @param string $type Mimetype of image
082 * @return array|bool Array with image dimensions if successful, false if not
083 */
084 public function getImageSize($file, $type = '')
085 {
086 // Reset values
087 $this->resetValues();
088
089 // Treat image type as unknown if extension or mime type is unknown
090 if (!preg_match('/\.([a-z0-9]+)$/i', $file, $match) && empty($type))
091 {
092 $this->getImagesizeUnknownType($file);
093 }
094 else
095 {
096 $extension = (empty($type) && isset($match[1])) ? $match[1] : preg_replace('/.+\/([a-z0-9-.]+)$/i', '$1', $type);
097
098 $this->getImageSizeByExtension($file, $extension);
099 }
100
101 return sizeof($this->size) > 1 ? $this->size : false;
102 }
103
104 /**
105 * Get dimensions of image if type is unknown
106 *
107 * @param string $filename Path to file
108 */
109 protected function getImagesizeUnknownType($filename)
110 {
111 // Grab the maximum amount of bytes we might need
112 $data = $this->getImage($filename, 0, Type\TypeJpeg::JPEG_MAX_HEADER_SIZE, false);
113
114 if ($data !== false)
115 {
116 $this->loadAllTypes();
117 foreach ($this->type as $imageType)
118 {
119 $imageType->getSize($filename);
120
121 if (sizeof($this->size) > 1)
122 {
123 break;
124 }
125 }
126 }
127 }
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 protected function getImageSizeByExtension($file, $extension)
136 {
137 $extension = strtolower($extension);
138 $this->loadExtension($extension);
139 if (isset($this->classMap[$extension]))
140 {
141 $this->classMap[$extension]->getSize($file);
142 }
143 }
144
145 /**
146 * Reset values to default
147 */
148 protected function resetValues()
149 {
150 $this->size = array();
151 $this->data = '';
152 }
153
154 /**
155 * Set mime type based on supplied image
156 *
157 * @param int $type Type of image
158 */
159 public function setImageType($type)
160 {
161 $this->size['type'] = $type;
162 }
163
164 /**
165 * Set size info
166 *
167 * @param array $size Array containing size info for image
168 */
169 public function setSize($size)
170 {
171 $this->size = $size;
172 }
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 public function getImage($filename, $offset, $length, $forceLength = true)
186 {
187 if (empty($this->data))
188 {
189 $this->data = @file_get_contents($filename, null, null, $offset, $length);
190 }
191
192 // Force length to expected one. Return false if data length
193 // is smaller than expected length
194 if ($forceLength === true)
195 {
196 return (strlen($this->data) < $length) ? false : substr($this->data, $offset, $length) ;
197 }
198
199 return empty($this->data) ? false : $this->data;
200 }
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()
208 {
209 return sizeof($this->size) > 1 ? $this->size : false;
210 }
211
212 /**
213 * Load all supported types
214 */
215 protected function loadAllTypes()
216 {
217 foreach ($this->supportedTypes as $imageType => $extension)
218 {
219 $this->loadType($imageType);
220 }
221 }
222
223 /**
224 * Load an image type by extension
225 *
226 * @param string $extension Extension of image
227 */
228 protected function loadExtension($extension)
229 {
230 if (isset($this->classMap[$extension]))
231 {
232 return;
233 }
234 foreach ($this->supportedTypes as $imageType => $extensions)
235 {
236 if (in_array($extension, $extensions, true))
237 {
238 $this->loadType($imageType);
239 }
240 }
241 }
242
243 /**
244 * Load an image type
245 *
246 * @param string $imageType Mimetype
247 */
248 protected function loadType($imageType)
249 {
250 if (isset($this->type[$imageType]))
251 {
252 return;
253 }
254
255 $className = '\FastImageSize\Type\Type' . mb_convert_case(mb_strtolower($imageType), MB_CASE_TITLE);
256 $this->type[$imageType] = new $className($this);
257
258 // Create class map
259 foreach ($this->supportedTypes[$imageType] as $ext)
260 {
261 /** @var Type\TypeInterface */
262 $this->classMap[$ext] = $this->type[$imageType];
263 }
264 }
265 }
266