find the size of an image without downloading the whole file. Supports batch requests.
MIT License
FasterImage finds the dimensions or filetype of a remote image file given its uri by fetching as little as needed, based on the excellent Ruby implementation by Stephen Sykes and PHP implementation by Tom Moor.
FasterImage uses the curl_muli* suite to run requests in parallel. Currently supports JPG, GIF, PNG, WEBP, BMP, PSD, TIFF, SVG, and ICO files.
$client = new \FasterImage\FasterImage();
$images = $client->batch([
'http://wwww.example.com/image1.jpg',
'http://wwww.example.com/image2.gif',
'http://wwww.example.com/image3.png',
'http://wwww.example.com/image4.bmp',
'http://wwww.example.com/image5.tiff',
'http://wwww.example.com/image6.psd',
'http://wwww.example.com/image7.webp',
'http://wwww.example.com/image8.ico',
'http://wwww.example.com/image9.cur',
'http://wwww.example.com/image10.svg'
]);
foreach ($images as $image) {
list($width,$height) = $image['size'];
}
composer require fasterimage/fasterimage
Alternatively, add "fasterimage/fasterimage": "~1.5"
to your composer.json
.PSD
, .ICO
+ .CUR
.webp
.tiff
and exceptions for unknown file types.jpg
, .bmp
, .gif
, .png
and parallel requests