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. |
|
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
TypeWebp.php
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\ImageReader;
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 * {@inheritdoc}
044 */
045 public function getSize(string $filename, ImageReader $imageReader): ?array
046 {
047 // Do not force length of header
048 $data = $imageReader->getImage($filename, 0, self::WEBP_HEADER_SIZE);
049
050 if ($data === false)
051 {
052 return null;
053 }
054
055 $this->size = array();
056
057 $webpFormat = substr($data, 15, 1);
058
059 if (!$this->hasWebpHeader($data) || !$this->isValidFormat($webpFormat))
060 {
061 return null;
062 }
063
064 $data = substr($data, 16, 14);
065
066 $this->setWebpSize($data, $webpFormat);
067 $this->size['type'] = IMAGETYPE_WEBP;
068
069 return $this->size;
070 }
071
072 /**
073 * Check if $data has valid WebP header
074 *
075 * @param string $data Image data
076 *
077 * @return bool True if $data has valid WebP header, false if not
078 */
079 protected function hasWebpHeader(string $data): bool
080 {
081 $riffSignature = substr($data, 0, self::LONG_SIZE);
082 $webpSignature = substr($data, 8, self::LONG_SIZE);
083 $vp8Signature = substr($data, 12, self::SHORT_SIZE + 1);
084
085 return !empty($data) && $riffSignature === self::WEBP_RIFF_HEADER &&
086 $webpSignature === self::WEBP_HEADER && $vp8Signature === self::VP8_HEADER;
087 }
088
089 /**
090 * Check if $format is a valid WebP format
091 *
092 * @param string $format Format string
093 * @return bool True if format is valid WebP format, false if not
094 */
095 protected function isValidFormat(string $format): bool
096 {
097 return in_array($format, array(self::WEBP_FORMAT_SIMPLE, self::WEBP_FORMAT_LOSSLESS, self::WEBP_FORMAT_EXTENDED));
098 }
099
100 /**
101 * Get webp size info depending on format type and set size array values
102 *
103 * @param string $data Data string
104 * @param string $format Format string
105 */
106 protected function setWebpSize(string $data, string $format): void
107 {
108 switch ($format)
109 {
110 case self::WEBP_FORMAT_SIMPLE:
111 $this->size = unpack('vwidth/vheight', substr($data, 10, 4));
112 break;
113
114 case self::WEBP_FORMAT_LOSSLESS:
115 // Lossless uses 14-bit values so we'll have to use bitwise shifting
116 $this->size = array(
117 'width' => ord($data[5]) + ((ord($data[6]) & 0x3F) << 8) + 1,
118 'height' => (ord($data[6]) >> 6) + (ord($data[7]) << 2) + ((ord($data[8]) & 0xF) << 10) + 1,
119 );
120 break;
121
122 case self::WEBP_FORMAT_EXTENDED:
123 // Extended uses 24-bit values cause 14-bit for lossless wasn't weird enough
124 $this->size = array(
125 'width' => ord($data[8]) + (ord($data[9]) << 8) + (ord($data[10]) << 16) + 1,
126 'height' => ord($data[11]) + (ord($data[12]) << 8) + (ord($data[13]) << 16) + 1,
127 );
128 break;
129 }
130 }
131 }
132