Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

getimagesize

Description

The getimagesize of Image for PHP get the size of an image.

Syntax

getimagesize(
    string $filename,
    array &$image_info = null
): array|false

Parameters

filename

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

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: The image_info only supports JFIF files.

Return

Returns an array with up to 7 elements.

Index 0 contains the width of the image.

Index 1 contains the height of the image.

Note: 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.

bits is the number of bits for each color. Not all image types will include the bits element.

channels will be 3 for RGB pictures and 4 for CMYK pictures. Not all image types will include the channels element.

mime is the correspondant MIME type of the image. This information can be used to deliver images with the correct HTTP Content-type header.

On failure, false is returned.

Examples

1 · filename

<?

$filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/jpg/2.jpg';

$return = getimagesize($filename);

print_r($return);

?>
Array
(
    [0] => 100
    [1] => 100
    [2] => 2
    [3] => width="100" height="100"
    [bits] => 8
    [channels] => 3
    [mime] => image/jpeg
)

2 · image_info

<?

$filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/jpg/2.jpg';

getimagesize($filename, $image_info);

print_r($image_info);

?>
Array
(
    [APP0] => JFIF``
    [APP13] => Photoshop 3.08BIM
DocumentTitle
UrgencyCategory
Subcatagories(SpecialInstructions7CreationDatePAuthorBylineUAuthorTitleZCity_StateeCountrygOTRiHeadlinenSourcesPhotoSourcet    CopyrightxCaptionz
CaptionWriter
)
HomeMenu