Augmentation vers version 3.3.0

This commit is contained in:
Gauvain Boiché
2020-03-31 15:31:03 +02:00
parent d926806907
commit a1864c0414
2618 changed files with 406015 additions and 31377 deletions

View File

@@ -74,25 +74,6 @@ class FastImageSize
/** @var array An array containing the classes of supported image types */
protected $type;
/**
* Constructor for fastImageSize class
*/
public function __construct()
{
foreach ($this->supportedTypes as $imageType => $extension)
{
$className = '\FastImageSize\Type\Type' . mb_convert_case(mb_strtolower($imageType), MB_CASE_TITLE);
$this->type[$imageType] = new $className($this);
// Create class map
foreach ($extension as $ext)
{
/** @var Type\TypeInterface */
$this->classMap[$ext] = $this->type[$imageType];
}
}
}
/**
* Get image dimensions of supplied image
*
@@ -132,6 +113,7 @@ class FastImageSize
if ($data !== false)
{
$this->loadAllTypes();
foreach ($this->type as $imageType)
{
$imageType->getSize($filename);
@@ -153,6 +135,7 @@ class FastImageSize
protected function getImageSizeByExtension($file, $extension)
{
$extension = strtolower($extension);
$this->loadExtension($extension);
if (isset($this->classMap[$extension]))
{
$this->classMap[$extension]->getSize($file);
@@ -225,4 +208,58 @@ class FastImageSize
{
return sizeof($this->size) > 1 ? $this->size : false;
}
/**
* Load all supported types
*/
protected function loadAllTypes()
{
foreach ($this->supportedTypes as $imageType => $extension)
{
$this->loadType($imageType);
}
}
/**
* Load an image type by extension
*
* @param string $extension Extension of image
*/
protected function loadExtension($extension)
{
if (isset($this->classMap[$extension]))
{
return;
}
foreach ($this->supportedTypes as $imageType => $extensions)
{
if (in_array($extension, $extensions, true))
{
$this->loadType($imageType);
}
}
}
/**
* Load an image type
*
* @param string $imageType Mimetype
*/
protected function loadType($imageType)
{
if (isset($this->type[$imageType]))
{
return;
}
$className = '\FastImageSize\Type\Type' . mb_convert_case(mb_strtolower($imageType), MB_CASE_TITLE);
$this->type[$imageType] = new $className($this);
// Create class map
foreach ($this->supportedTypes[$imageType] as $ext)
{
/** @var Type\TypeInterface */
$this->classMap[$ext] = $this->type[$imageType];
}
}
}

View File

@@ -15,7 +15,7 @@ class TypeJpeg extends TypeBase
{
/** @var int JPEG max header size. Headers can be bigger, but we'll abort
* going through the header after this */
const JPEG_MAX_HEADER_SIZE = 124576;
const JPEG_MAX_HEADER_SIZE = 786432; // = 768 kiB
/** @var string JPEG header */
const JPEG_HEADER = "\xFF\xD8";
@@ -43,17 +43,6 @@ class TypeJpeg extends TypeBase
"\xCF"
);
/** @var array JPEG APP markers */
protected $appMarkers = array(
"\xE0",
"\xE1",
"\xE2",
"\xE3",
"\xEC",
"\xED",
"\xEE",
);
/** @var string|bool JPEG data stream */
protected $data = '';

View File

@@ -14,8 +14,8 @@ namespace FastImageSize\Type;
class TypeTif extends TypeBase
{
/** @var int TIF header size. The header might be larger but the dimensions
* should be in the first 51200 bytes */
const TIF_HEADER_SIZE = 51200;
* should be in the first 256 kiB bytes */
const TIF_HEADER_SIZE = 262144;
/** @var int TIF tag for image height */
const TIF_TAG_IMAGE_HEIGHT = 257;
@@ -23,15 +23,6 @@ class TypeTif extends TypeBase
/** @var int TIF tag for image width */
const TIF_TAG_IMAGE_WIDTH = 256;
/** @var int TIF tag for exif IFD offset */
const TIF_TAG_EXIF_OFFSET = 34665;
/** @var int TIF tag for Image X resolution in pixels */
const TIF_TAG_EXIF_IMAGE_WIDTH = 0xA002;
/** @var int TIF tag for Image Y resolution in pixels */
const TIF_TAG_EXIF_IMAGE_HEIGHT = 0xA003;
/** @var int TIF tag type for short */
const TIF_TAG_TYPE_SHORT = 3;
@@ -77,7 +68,12 @@ class TypeTif extends TypeBase
list(, $offset) = unpack($this->typeLong, substr($data, self::LONG_SIZE, self::LONG_SIZE));
// Get size of IFD
list(, $sizeIfd) = unpack($this->typeShort, substr($data, $offset, self::SHORT_SIZE));
$ifdSizeInfo = substr($data, $offset, self::SHORT_SIZE);
if (empty($ifdSizeInfo))
{
return;
}
list(, $sizeIfd) = unpack($this->typeShort, $ifdSizeInfo);
// Skip 2 bytes that define the IFD size
$offset += self::SHORT_SIZE;