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 |
TypeIff.php
001 <?php
002
003 /**
004 * fast-image-size image type iff
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 class TypeIff extends TypeBase
015 {
016 /** @var int IFF header size. Grab more than what should be needed to make
017 * sure we have the necessary data */
018 const IFF_HEADER_SIZE = 32;
019
020 /** @var string IFF header for Amiga type */
021 const IFF_HEADER_AMIGA = 'FORM';
022
023 /** @var string IFF header for Maya type */
024 const IFF_HEADER_MAYA = 'FOR4';
025
026 /** @var string IFF BTMHD for Amiga type */
027 const IFF_AMIGA_BTMHD = 'BMHD';
028
029 /** @var string IFF BTMHD for Maya type */
030 const IFF_MAYA_BTMHD = 'BHD';
031
032 /** @var string PHP pack format for unsigned short */
033 const PACK_UNSIGNED_SHORT = 'n';
034
035 /** @var string PHP pack format for unsigned long */
036 const PACK_UNSIGNED_LONG = 'N';
037
038 /** @var string BTMHD of current image */
039 protected $btmhd;
040
041 /** @var int Size of current BTMHD */
042 protected $btmhdSize;
043
044 /** @var string Current byte type */
045 protected $byteType;
046
047 /**
048 * {@inheritdoc}
049 */
050 public function getSize($filename)
051 {
052 $data = $this->fastImageSize->getImage($filename, 0, self::IFF_HEADER_SIZE);
053
054 $signature = $this->getIffSignature($data);
055
056 // Check if image is IFF
057 if ($signature === false)
058 {
059 return;
060 }
061
062 // Set type constraints
063 $this->setTypeConstraints($signature);
064
065 // Get size from data
066 $btmhdPosition = strpos($data, $this->btmhd);
067 $size = unpack("{$this->byteType}width/{$this->byteType}height", substr($data, $btmhdPosition + self::LONG_SIZE + strlen($this->btmhd), $this->btmhdSize));
068
069 $this->fastImageSize->setSize($size);
070 $this->fastImageSize->setImageType(IMAGETYPE_IFF);
071 }
072
073 /**
074 * Get IFF signature from data string
075 *
076 * @param string|bool $data Image data string
077 *
078 * @return false|string Signature if file is a valid IFF file, false if not
079 */
080 protected function getIffSignature($data)
081 {
082 $signature = substr($data, 0, self::LONG_SIZE);
083
084 // Check if image is IFF
085 if ($signature !== self::IFF_HEADER_AMIGA && $signature !== self::IFF_HEADER_MAYA)
086 {
087 return false;
088 }
089 else
090 {
091 return $signature;
092 }
093 }
094
095 /**
096 * Set type constraints for current image
097 *
098 * @param string $signature IFF signature of image
099 */
100 protected function setTypeConstraints($signature)
101 {
102 // Amiga version of IFF
103 if ($signature === 'FORM')
104 {
105 $this->btmhd = self::IFF_AMIGA_BTMHD;
106 $this->btmhdSize = self::LONG_SIZE;
107 $this->byteType = self::PACK_UNSIGNED_SHORT;
108 }
109 // Maya version
110 else
111 {
112 $this->btmhd = self::IFF_MAYA_BTMHD;
113 $this->btmhdSize = self::LONG_SIZE * 2;
114 $this->byteType = self::PACK_UNSIGNED_LONG;
115 }
116 }
117 }
118