PHP | getimagesize() Function (original) (raw)

Last Updated : 11 Jul, 2025

The getimagesize() function in PHP is an inbuilt function which is used to get the size of an image. This function accepts the filename as a parameter and determines the image size and returns the dimensions with the file type and height/width of image.Syntax:

array getimagesize( filename,filename, filename,image_info )

Parameters: This function accepts two parameters as mentioned above and described below:

Return Value: It returns the dimensions along with the file type and a height/width text string.Exceptions:

Below programs illustrate the getimagesize() function in PHP:Note: The image (geeks.png) given below used in the following program.geeks image Program 1:

php `

`

Output:

Array ( [0] => 667 [1] => 184 [2] => 3 [3] => width="667" height="184" [bits] => 8 [mime] => image/png )

Program 2:

php `

height,height, height,type, $attr) = getimagesize("geeks.png"); // Displaying dimensions of the image echo "Width of image : " . $width . "
"; echo "Height of image : " . $height . "
"; echo "Image type :" . $type . "
"; echo "Image attribute :" .$attr; ?>

`

Output:

Width of image : 667 Height of image : 184 Image type :3 Image attribute :width="667" height="184"

Reference: https://www.php.net/manual/en/function.getimagesize.php

PHP is a server-side scripting language designed specifically for web development. You can learn PHP from the ground up by following this PHP Tutorial and PHP Examples.