Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

FastImageSize.php

Zuletzt modifiziert: 01.05.2026, 11:26 - Dateigröße: 6.63 KiB


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  use FastImageSize\Type\TypeInterface;
015   
016  class FastImageSize
017  {
018      /** @var array Size info that is returned */
019      protected $size = array();
020   
021      /** @var array List of supported image types and associated image types */
022      protected $supportedTypes = array(
023          'png'    => array('png'),
024          'gif'    => array('gif'),
025          'jpeg'    => array(
026                  'jpeg',
027                  'jpg',
028                  'jpe',
029                  'jif',
030                  'jfif',
031                  'jfi',
032              ),
033          'jp2'    => array(
034                  'jp2',
035                  'j2k',
036                  'jpf',
037                  'jpg2',
038                  'jpx',
039                  'jpm',
040              ),
041          'psd'    => array(
042                  'psd',
043                  'photoshop',
044              ),
045          'bmp'    => array('bmp'),
046          'tif'    => array(
047                  'tif',
048                  'tiff',
049              ),
050          'wbmp'    => array(
051                  'wbm',
052                  'wbmp',
053                  'vnd.wap.wbmp',
054              ),
055          'iff'    => array(
056                  'iff',
057                  'x-iff',
058          ),
059          'ico'    => array(
060                  'ico',
061                  'vnd.microsoft.icon',
062                  'x-icon',
063                  'icon',
064          ),
065          'webp'    => array(
066                  'webp',
067          )
068      );
069   
070      /** @var array Class map that links image extensions/mime types to class */
071      protected $classMap;
072   
073      /** @var array An array containing the classes of supported image types */
074      protected $type;
075   
076      /** @var ImageReader */
077      protected $imageReader;
078   
079      /**
080       * Constructor
081       */
082      public function __construct()
083      {
084          $this->imageReader = new ImageReader();
085      }
086   
087      /**
088       * Get image dimensions of supplied image
089       *
090       * @param string $file Path to image that should be checked
091       * @param string $type Mimetype of image
092       * @return array|bool Array with image dimensions if successful, false if not
093       */
094      public function getImageSize(string $file, string $type = '')
095      {
096          // Reset values
097          $this->resetValues();
098   
099          // Treat image type as unknown if extension or mime type is unknown
100          $fileExtension = $this->getFileExtension($file);
101          if (empty($fileExtension) && empty($type))
102          {
103              $this->getImagesizeUnknownType($file);
104          }
105          else
106          {
107              $extension = $this->selectImageExtension($fileExtension, $type);
108   
109              $this->getImageSizeByExtension($file, $extension);
110              
111              if (count($this->size) < 2)
112              {
113                  $this->imageReader->reset();
114                  $this->getImagesizeUnknownType($file);
115              }
116          }
117   
118          return count($this->size) > 1 ? $this->size : false;
119      }
120   
121      /**
122       * Get file extension from supplied file path
123       *
124       * @param string $file Path to file
125       * @return string File extension if found, empty string if not
126       */
127      protected function getFileExtension(string $file): string
128      {
129          if (preg_match('/\.([a-z0-9]+)$/i', $file, $match))
130          {
131              return $match[1];
132          }
133   
134          return '';
135      }
136   
137      /**
138       * Select image extension to use for retrieving dimensions
139       *
140       * @param string $fileExtension File extension from file path
141       * @param string $type Mimetype of image
142       * @return string Image extension to use for retrieving dimensions
143       */
144      protected function selectImageExtension(string $fileExtension, string $type): string
145      {
146          return (empty($type) && !empty($fileExtension)) ? $fileExtension : preg_replace('/.+\/([a-z0-9-.]+)$/i', '$1', $type);
147      }
148   
149      /**
150       * Get dimensions of image if type is unknown
151       *
152       * @param string $filename Path to file
153       */
154      protected function getImagesizeUnknownType(string $filename)
155      {
156          // Grab the maximum amount of bytes we might need
157          $data = $this->getImage($filename, 0, Type\TypeJpeg::JPEG_MAX_HEADER_SIZE, false);
158   
159          if ($data !== false)
160          {
161              $this->loadAllTypes();
162              foreach ($this->type as $imageType)
163              {
164                  $result = $imageType->getSize($filename, $this->imageReader);
165                  if ($result)
166                  {
167                      $this->size = $result;
168                      break;
169                  }
170              }
171          }
172      }
173   
174      /**
175       * Get image size by file extension
176       *
177       * @param string $file Path to image that should be checked
178       * @param string $extension Extension/type of image
179       */
180      protected function getImageSizeByExtension(string $file, string $extension)
181      {
182          $extension = strtolower($extension);
183          $this->loadExtension($extension);
184          if (isset($this->classMap[$extension]))
185          {
186              $result = $this->type[$this->classMap[$extension]]->getSize($file, $this->imageReader);
187              if ($result)
188              {
189                  $this->size = $result;
190              }
191          }
192      }
193   
194      /**
195       * Reset values to default
196       */
197      protected function resetValues()
198      {
199          $this->size = array();
200          $this->imageReader->reset();
201      }
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, must be greater than 0
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      public function getImage(string $filename, int $offset, int $length, bool $forceLength = true)
215      {
216          return $this->imageReader->getImage($filename, $offset, $length, $forceLength);
217      }
218   
219      /**
220       * Set stream context options for retrieving remote images
221       *
222       * @param array $options Stream context options
223       */
224      public function setStreamContextOptions(array $options)
225      {
226          $this->imageReader->setStreamContextOptions($options);
227      }
228   
229      /**
230       * Load all supported types
231       */
232      protected function loadAllTypes()
233      {
234          foreach ($this->supportedTypes as $imageType => $extension)
235          {
236              $this->loadType($imageType);
237          }
238      }
239   
240      /**
241       * Load an image type by extension
242       *
243       * @param string $extension Extension of image
244       */
245      protected function loadExtension(string $extension)
246      {
247          if (isset($this->classMap[$extension]))
248          {
249              return;
250          }
251          foreach ($this->supportedTypes as $imageType => $extensions)
252          {
253              if (in_array($extension, $extensions, true))
254              {
255                  $this->loadType($imageType);
256              }
257          }
258      }
259   
260      /**
261       * Load an image type
262       *
263       * @param string $imageType Mimetype
264       */
265      protected function loadType(string $imageType): void
266      {
267          if (isset($this->type[$imageType]))
268          {
269              return;
270          }
271   
272          $typeInstance = $this->loadTypeClass($imageType);
273          if (!$typeInstance)
274          {
275              return;
276          }
277   
278          $this->type[$imageType] = $typeInstance;
279   
280          // Create class map
281          foreach ($this->supportedTypes[$imageType] as $ext)
282          {
283              $this->classMap[$ext] = $imageType;
284          }
285      }
286   
287      /**
288       * Load class for an image type
289       *
290       * @param string $imageType Mimetype
291       * @return TypeInterface|null Instance of type class if successful, null if not
292       */
293      protected function loadTypeClass(string $imageType): ?TypeInterface
294      {
295          $className = '\FastImageSize\Type\Type' . ucfirst($imageType);
296          $filePath = __DIR__ . '/Type/Type' . ucfirst($imageType) . '.php';
297          if (!class_exists($className, false))
298          {
299              if (is_file($filePath))
300              {
301                  require_once $filePath;
302              }
303              else
304              {
305                  return null;
306              }
307          }
308   
309          return new $className();
310      }
311  }
312