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 |
TypeTif.php
001 <?php
002
003 /**
004 * fast-image-size image type tif
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 TypeTif extends TypeBase
015 {
016 /** @var int TIF header size. The header might be larger but the dimensions
017 * should be in the first 256 kiB bytes */
018 const TIF_HEADER_SIZE = 262144;
019
020 /** @var int TIF tag for image height */
021 const TIF_TAG_IMAGE_HEIGHT = 257;
022
023 /** @var int TIF tag for image width */
024 const TIF_TAG_IMAGE_WIDTH = 256;
025
026 /** @var int TIF tag type for short */
027 const TIF_TAG_TYPE_SHORT = 3;
028
029 /** @var int TIF IFD entry size */
030 const TIF_IFD_ENTRY_SIZE = 12;
031
032 /** @var string TIF signature of intel type */
033 const TIF_SIGNATURE_INTEL = 'II';
034
035 /** @var string TIF signature of motorola type */
036 const TIF_SIGNATURE_MOTOROLA = 'MM';
037
038 /** @var array Size info array */
039 protected $size;
040
041 /** @var string Bit type of long field */
042 public $typeLong;
043
044 /** @var string Bit type of short field */
045 public $typeShort;
046
047 /**
048 * {@inheritdoc}
049 */
050 public function getSize($filename)
051 {
052 // Do not force length of header
053 $data = $this->fastImageSize->getImage($filename, 0, self::TIF_HEADER_SIZE, false);
054
055 $this->size = array();
056
057 $signature = substr($data, 0, self::SHORT_SIZE);
058
059 if (!in_array($signature, array(self::TIF_SIGNATURE_INTEL, self::TIF_SIGNATURE_MOTOROLA)))
060 {
061 return;
062 }
063
064 // Set byte type
065 $this->setByteType($signature);
066
067 // Get offset of IFD
068 list(, $offset) = unpack($this->typeLong, substr($data, self::LONG_SIZE, self::LONG_SIZE));
069
070 // Get size of IFD
071 $ifdSizeInfo = substr($data, $offset, self::SHORT_SIZE);
072 if (empty($ifdSizeInfo))
073 {
074 return;
075 }
076 list(, $sizeIfd) = unpack($this->typeShort, $ifdSizeInfo);
077
078 // Skip 2 bytes that define the IFD size
079 $offset += self::SHORT_SIZE;
080
081 // Ensure size can't exceed data length
082 $sizeIfd = min($sizeIfd, floor((strlen($data) - $offset) / self::TIF_IFD_ENTRY_SIZE));
083
084 // Filter through IFD
085 for ($i = 0; $i < $sizeIfd; $i++)
086 {
087 // Get IFD tag
088 $type = unpack($this->typeShort, substr($data, $offset, self::SHORT_SIZE));
089
090 // Get field type of tag
091 $fieldType = unpack($this->typeShort . 'type', substr($data, $offset + self::SHORT_SIZE, self::SHORT_SIZE));
092
093 // Get IFD entry
094 $ifdValue = substr($data, $offset + 2 * self::LONG_SIZE, self::LONG_SIZE);
095
096 // Set size of field
097 $this->setSizeInfo($type[1], $fieldType['type'], $ifdValue);
098
099 $offset += self::TIF_IFD_ENTRY_SIZE;
100 }
101
102 $this->fastImageSize->setSize($this->size);
103 }
104
105 /**
106 * Set byte type based on signature in header
107 *
108 * @param string $signature Header signature
109 */
110 public function setByteType($signature)
111 {
112 if ($signature === self::TIF_SIGNATURE_INTEL)
113 {
114 $this->typeLong = 'V';
115 $this->typeShort = 'v';
116 $this->size['type'] = IMAGETYPE_TIFF_II;
117 }
118 else
119 {
120 $this->typeLong = 'N';
121 $this->typeShort = 'n';
122 $this->size['type'] = IMAGETYPE_TIFF_MM;
123 }
124 }
125
126 /**
127 * Set size info
128 *
129 * @param int $dimensionType Type of dimension. Either width or height
130 * @param int $fieldLength Length of field. Either short or long
131 * @param string $ifdValue String value of IFD field
132 */
133 protected function setSizeInfo($dimensionType, $fieldLength, $ifdValue)
134 {
135 // Set size of field
136 $fieldSize = $fieldLength === self::TIF_TAG_TYPE_SHORT ? $this->typeShort : $this->typeLong;
137
138 // Get actual dimensions from IFD
139 if ($dimensionType === self::TIF_TAG_IMAGE_HEIGHT)
140 {
141 $this->size = array_merge($this->size, unpack($fieldSize . 'height', $ifdValue));
142 }
143 else if ($dimensionType === self::TIF_TAG_IMAGE_WIDTH)
144 {
145 $this->size = array_merge($this->size, unpack($fieldSize . 'width', $ifdValue));
146 }
147 }
148 }
149