Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
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 |
FastImageSize.php
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 class FastImageSize
015 {
016 /** @var array Size info that is returned */
017 protected $size = array();
018
019 /** @var string Data retrieved from remote */
020 protected $data = '';
021
022 /** @var array List of supported image types and associated image types */
023 protected $supportedTypes = array(
024 'png' => array('png'),
025 'gif' => array('gif'),
026 'jpeg' => array(
027 'jpeg',
028 'jpg',
029 'jpe',
030 'jif',
031 'jfif',
032 'jfi',
033 ),
034 'jp2' => array(
035 'jp2',
036 'j2k',
037 'jpf',
038 'jpg2',
039 'jpx',
040 'jpm',
041 ),
042 'psd' => array(
043 'psd',
044 'photoshop',
045 ),
046 'bmp' => array('bmp'),
047 'tif' => array(
048 'tif',
049 'tiff',
050 ),
051 'wbmp' => array(
052 'wbm',
053 'wbmp',
054 'vnd.wap.wbmp',
055 ),
056 'iff' => array(
057 'iff',
058 'x-iff',
059 ),
060 'ico' => array(
061 'ico',
062 'vnd.microsoft.icon',
063 'x-icon',
064 'icon',
065 ),
066 );
067
068 /** @var array Class map that links image extensions/mime types to class */
069 protected $classMap;
070
071 /** @var array An array containing the classes of supported image types */
072 protected $type;
073
074 /**
075 * Constructor for fastImageSize class
076 */
077 public function __construct()
078 {
079 foreach ($this->supportedTypes as $imageType => $extension)
080 {
081 $className = '\FastImageSize\Type\Type' . mb_convert_case(mb_strtolower($imageType), MB_CASE_TITLE);
082 $this->type[$imageType] = new $className($this);
083
084 // Create class map
085 foreach ($extension as $ext)
086 {
087 /** @var Type\TypeInterface */
088 $this->classMap[$ext] = $this->type[$imageType];
089 }
090 }
091 }
092
093 /**
094 * Get image dimensions of supplied image
095 *
096 * @param string $file Path to image that should be checked
097 * @param string $type Mimetype of image
098 * @return array|bool Array with image dimensions if successful, false if not
099 */
100 public function getImageSize($file, $type = '')
101 {
102 // Reset values
103 $this->resetValues();
104
105 // Treat image type as unknown if extension or mime type is unknown
106 if (!preg_match('/\.([a-z0-9]+)$/i', $file, $match) && empty($type))
107 {
108 $this->getImagesizeUnknownType($file);
109 }
110 else
111 {
112 $extension = (isset($match[1])) ? $match[1] : preg_replace('/.+\/([a-z0-9-.]+)$/i', '$1', $type);
113
114 $this->getImageSizeByExtension($file, $extension);
115 }
116
117 return sizeof($this->size) > 1 ? $this->size : false;
118 }
119
120 /**
121 * Get dimensions of image if type is unknown
122 *
123 * @param string $filename Path to file
124 */
125 protected function getImagesizeUnknownType($filename)
126 {
127 // Grab the maximum amount of bytes we might need
128 $data = $this->getImage($filename, 0, Type\TypeJpeg::JPEG_MAX_HEADER_SIZE, false);
129
130 if ($data !== false)
131 {
132 foreach ($this->type as $imageType)
133 {
134 $imageType->getSize($filename);
135
136 if (sizeof($this->size) > 1)
137 {
138 break;
139 }
140 }
141 }
142 }
143
144 /**
145 * Get image size by file extension
146 *
147 * @param string $file Path to image that should be checked
148 * @param string $extension Extension/type of image
149 */
150 protected function getImageSizeByExtension($file, $extension)
151 {
152 $extension = strtolower($extension);
153 if (isset($this->classMap[$extension]))
154 {
155 $this->classMap[$extension]->getSize($file);
156 }
157 }
158
159 /**
160 * Reset values to default
161 */
162 protected function resetValues()
163 {
164 $this->size = array();
165 $this->data = '';
166 }
167
168 /**
169 * Set mime type based on supplied image
170 *
171 * @param int $type Type of image
172 */
173 public function setImageType($type)
174 {
175 $this->size['type'] = $type;
176 }
177
178 /**
179 * Set size info
180 *
181 * @param array $size Array containing size info for image
182 */
183 public function setSize($size)
184 {
185 $this->size = $size;
186 }
187
188 /**
189 * Get image from specified path/source
190 *
191 * @param string $filename Path to image
192 * @param int $offset Offset at which reading of the image should start
193 * @param int $length Maximum length that should be read
194 * @param bool $forceLength True if the length needs to be the specified
195 * length, false if not. Default: true
196 *
197 * @return false|string Image data or false if result was empty
198 */
199 public function getImage($filename, $offset, $length, $forceLength = true)
200 {
201 if (empty($this->data))
202 {
203 $this->data = @file_get_contents($filename, null, null, $offset, $length);
204 }
205
206 // Force length to expected one. Return false if data length
207 // is smaller than expected length
208 if ($forceLength === true)
209 {
210 return (strlen($this->data) < $length) ? false : substr($this->data, $offset, $length) ;
211 }
212
213 return empty($this->data) ? false : $this->data;
214 }
215
216 /**
217 * Get return data
218 *
219 * @return array|bool Size array if dimensions could be found, false if not
220 */
221 protected function getReturnData()
222 {
223 return sizeof($this->size) > 1 ? $this->size : false;
224 }
225 }
226