PHP function getimagesize - image size

26. 11. 2019

Obsah článku

This function returns the physical dimensions of the image.


Parameter Data type Default value Note
$filename string not 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.
$imageinfo array null 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.

Return values


|bool an array with 7 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 might not be able to properly determine the image size. getimagesize will return zero for width and height in these cases.

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. This information can be used to deliver images with correct the HTTP Content-type header: getimagesize and MIME types ]]>

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.

Other resources

Official getimagesize documentation

Jan Barášek   Více o autorovi

Autor článku pracuje jako seniorní vývojář a software architekt v Praze. Navrhuje a spravuje velké webové aplikace, které znáte a používáte. Od roku 2009 nabral bohaté zkušenosti, které tímto webem předává dál.

Rád vám pomůžu:

Související články


V jiných jazycích