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

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

TypeWebp.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 3.55 KiB


001  <?php
002   
003  /**
004   * fast-image-size image type webp
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\Type;
013   
014  use \FastImageSize\FastImageSize;
015   
016  class TypeWebp extends TypeBase
017  {
018      /** @var string RIFF header */
019      const WEBP_RIFF_HEADER = "RIFF";
020   
021      /** @var string Webp header */
022      const WEBP_HEADER = "WEBP";
023   
024      /** @var string VP8 chunk header */
025      const VP8_HEADER = "VP8";
026   
027      /** @var string Simple(lossy) webp format */
028      const WEBP_FORMAT_SIMPLE = ' ';
029   
030      /** @var string Lossless webp format */
031      const WEBP_FORMAT_LOSSLESS = 'L';
032   
033      /** @var string Extended webp format */
034      const WEBP_FORMAT_EXTENDED = 'X';
035   
036      /** @var int WEBP header size needed for retrieving image size */
037      const WEBP_HEADER_SIZE = 30;
038   
039      /** @var array Size info array */
040      protected $size;
041   
042      /**
043       * Constructor for webp image type. Adds missing constant if necessary.
044       *
045       * @param FastImageSize $fastImageSize
046       */
047      public function __construct(FastImageSize $fastImageSize)
048      {
049          parent::__construct($fastImageSize);
050   
051          if (!defined('IMAGETYPE_WEBP'))
052          {
053              define('IMAGETYPE_WEBP', 18);
054          }
055      }
056   
057      /**
058       * {@inheritdoc}
059       */
060      public function getSize($filename)
061      {
062          // Do not force length of header
063          $data = $this->fastImageSize->getImage($filename, 0, self::WEBP_HEADER_SIZE);
064   
065          $this->size = array();
066   
067          $webpFormat = substr($data, 15, 1);
068   
069          if (!$this->hasWebpHeader($data) || !$this->isValidFormat($webpFormat))
070          {
071              return;
072          }
073   
074          $data = substr($data, 16, 14);
075   
076          $this->getWebpSize($data, $webpFormat);
077   
078          $this->fastImageSize->setSize($this->size);
079          $this->fastImageSize->setImageType(IMAGETYPE_WEBP);
080      }
081   
082      /**
083       * Check if $data has valid WebP header
084       *
085       * @param string $data Image data
086       *
087       * @return bool True if $data has valid WebP header, false if not
088       */
089      protected function hasWebpHeader($data)
090      {
091          $riffSignature = substr($data, 0, self::LONG_SIZE);
092          $webpSignature = substr($data, 8, self::LONG_SIZE);
093          $vp8Signature = substr($data, 12, self::SHORT_SIZE + 1);
094   
095          return !empty($data) && $riffSignature === self::WEBP_RIFF_HEADER &&
096              $webpSignature === self::WEBP_HEADER && $vp8Signature === self::VP8_HEADER;
097      }
098   
099      /**
100       * Check if $format is a valid WebP format
101       *
102       * @param string $format Format string
103       * @return bool True if format is valid WebP format, false if not
104       */
105      protected function isValidFormat($format)
106      {
107          return in_array($format, array(self::WEBP_FORMAT_SIMPLE, self::WEBP_FORMAT_LOSSLESS, self::WEBP_FORMAT_EXTENDED));
108      }
109   
110      /**
111       * Get webp size info depending on format type and set size array values
112       *
113       * @param string $data Data string
114       * @param string $format Format string
115       */
116      protected function getWebpSize($data, $format)
117      {
118          switch ($format)
119          {
120              case self::WEBP_FORMAT_SIMPLE:
121                  $this->size = unpack('vwidth/vheight', substr($data, 10, 4));
122              break;
123   
124              case self::WEBP_FORMAT_LOSSLESS:
125                  // Lossless uses 14-bit values so we'll have to use bitwise shifting
126                  $this->size = array(
127                      'width'        => ord($data[5]) + ((ord($data[6]) & 0x3F) << 8) + 1,
128                      'height'    => (ord($data[6]) >> 6) + (ord($data[7]) << 2) + ((ord($data[8]) & 0xF) << 10) + 1,
129                  );
130              break;
131   
132              case self::WEBP_FORMAT_EXTENDED:
133                  // Extended uses 24-bit values cause 14-bit for lossless wasn't weird enough
134                  $this->size = array(
135                      'width'        => ord($data[8]) + (ord($data[9]) << 8) + (ord($data[10]) << 16) + 1,
136                      'height'    => ord($data[11]) + (ord($data[12]) << 8) + (ord($data[13]) << 16) + 1,
137                  );
138              break;
139          }
140      }
141  }
142