loumray / fastimagesize
This package provides a getimagesize function that aims to match the usage of PHP getimagesize while trying to avoid the performance cost of downloading the complete file.
Installs: 7 346
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 20
Open Issues: 0
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: ^4.8|^5.0|^6.0
This package is not auto-updated.
Last update: 2024-11-10 04:58:34 UTC
README
This package provides a getimagesize function that aims to match the usage of PHP getimagesize while trying to avoid the performance cost of downloading the complete file.
It currently supports the following image types:
- BMP
- GIF
- ICO
- IFF
- JPEG 2000
- JPEG
- PNG
- PSD
- TIF/TIFF
- WBMP
Requirements
PHP 5.3.0 or greater.
Installation
composer require loumray/fastimagesize
Usage
array \FastImageSize\getimagesize(String filepath);
Return array as per PHP getimagesize function
Index 0 and 1 contains respectively the width and the height of the image.
Index 2 is one of the IMAGETYPE_XXX constants indicating the type of the image.
Index 3 is a text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.
mime is the correspondant MIME type of the image.
It will however not return channels and bits index that getimagesize sometimes returns.
Just like for PHP getimagesize, you can pass any local or remote image to this library as long as it's readable.
Backward Compatibility
For backward compatibility, the FastImageSize class is still available. So you can still make use of
$FastImageSize = new \FastImageSize\FastImageSize();
$imageSize = $FastImageSize->getImageSize(String filepath);
And this will return the array size
array(
'width' => 16,
'height' => 16,
'type' => IMAGETYPE_PNG,
);