marc1706/fast-image-size

fast-image-size is a PHP library that does almost everything PHP's getimagesize() does but without the large overhead of downloading the complete file.

Maintainers

👁 marc1706

Package info

github.com/marc1706/fast-image-size

Homepage

pkg:composer/marc1706/fast-image-size

Statistics

Installs: 9 509 541

Dependents: 23

Suggesters: 0

Stars: 95

Open Issues: 3

v1.3.1 2026-03-28 15:26 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 35c193f56d3a3abaf441918ea4eda7cd5d89d443

phpimagefastsizegetimagesizeimagesize


README

About

fast-image-size is a PHP library that does almost everything PHP's getimagesize() does but without the large overhead of downloading the complete file.

It currently supports the following image types:

  • BMP
  • GIF
  • ICO
  • IFF
  • JPEG 2000
  • JPEG
  • PNG
  • PSD
  • TIF/TIFF
  • WBMP
  • WebP

Requirements

PHP 7.2.0 or newer is required for this library to work.

Installation

It is recommend to install the library using composer. Just add the following snippet to your composer.json:

 "require": {
 "marc1706/fast-image-size": "^1.3"
 },

Usage

Using the fast-image-size library is rather straightforward. Just create a new instance of the main class:

$FastImageSize = new \FastImageSize\FastImageSize();

Afterwards, you can check images using the getImageSize() method:

$imageSize = $FastImageSize->getImageSize('https://example.com/some_random_image.jpg');

You can pass any local or remote image to this library as long as it's readable.

If the library is able to determine the image size, it will return an array with the following structure (values and type might of course differ depending on your image):

$imageSize = array(
	'width' => 16,
	'height' => 16,
	'type' => IMAGETYPE_PNG,
);

Configuration

You can set stream context options using the setStreamContextOptions() method. This allows you to customize the request, for example by setting a timeout for remote images:

$imageSize->setStreamContextOptions([
	'http' => [
		'timeout' => 5.0,
	],
]);

Automated Tests

The library is being tested using unit tests to prevent possible issues.

👁 CI
👁 Code Coverage
👁 Scrutinizer Code Quality

License

The MIT License (MIT)

Credits

Sample files of WebP format by Google: WebP Image Galleries