getimagesize
Get the size of an image.
getimagesize Function synopsis
getimagesize(string $filename, &$image_info = null): array|false
Parameters
$filename
Typestring
This parameter specifies the file you wish to retrieve information about. It can reference a local file or (configuration permitting) a remote file using one of the supported streams.
$image_info
Passed by reference, OptionalDefault valuenull
This optional parameter allows you to extract some extended
information from the image file. Currently, this will return the
different JPG APP markers as an associative array.
Some programs use these APP markers to embed text information in
images. A very common one is to embed
IPTC information in the APP13 marker.
You can use the iptcparse function to parse the
binary APP13 marker into something readable.
Note that the parameter
$image_infois passed by reference, and contains additional/updated context data that may be useful.
Return value
Typearray|false
Returns an array with up to 7 elements. Not all image types will include
the channels and bits elements.
Index 0 and 1 contains respectively the width and the height of the image.
Some formats may contain no image or may contain multiple images. In these
cases, [`getimagesize`](/codex/getimagesize) might not be able to properly
determine the image size. [`getimagesize`](/codex/getimagesize) will return
zero for width and height in these cases.
Index 2 is one of the IMAGETYPE_* 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.
This information can be used to deliver images with the correct HTTP
Content-type header:
channels will be 3 for RGB pictures and 4 for CMYK
pictures.
bits is the number of bits for each color.
For some image types, the presence of channels and
bits values can be a bit
confusing. As an example, GIF always uses 3 channels
per pixel, but the number of bits per pixel cannot be calculated for an
animated GIF with a global color table.
On failure, false is returned.
Changes to the getimagesize Function
PHP 8.0
- Return type added:
array|false - Parameter name of parameter #1 changed:
$imagefileto$filename - Parameter type added for parameter #1 (
$filename):string - Parameter name of parameter #2 changed:
$infoto$image_info - Parameter default value added for position #2 (
$image_info):null
- getimagesize($imagefile, &$info)
+ getimagesize(string $filename, &$image_info = null): array|false getimagesize Function Availability
getimagesize Function Availability| PHP Version | Availability |
|---|---|
| PHP 8.6Future Release | Yes |
| PHP 8.5Upcoming Release | Yes |
| PHP 8.4Supported (Latest) | Yes |
| PHP 8.3Supported | Yes |
| PHP 8.2Security-Fixes Only | Yes |
| PHP 8.1Security-Fixes Only | Yes |
| PHP 8.0Unsupported | Yes |
| PHP 7.4Unsupported | Yes |
| PHP 7.3Unsupported | Yes |
| PHP 7.2Unsupported | Yes |
| PHP 7.1Unsupported | Yes |
| PHP 7.0Unsupported | Yes |
| PHP 5.6Unsupported | Yes |
| PHP 5.5Unsupported | Yes |
| PHP 5.4Unsupported | Yes |
| PHP 5.3Unsupported | Yes |