The getimagesize() function is used to obtain the image size and related information. It returns an array if successful. If it fails, it returns FALSE and generates an E_WARNING level error message.
Syntax format:
array getimagesize ( string $filename [, array &$imageinfo ] )
The getimagesize() function will determine the size of any GIF, JPG, PNG, SWF, SWC, PSD, TIFF, BMP, IFF, JP2, JPX, JB2, JPC, XBM or WBMP image file and return the size of the image as well as the file type and image height and width.
<?phplist($width, $height, $type, $attr) = getimagesize("codercto-logo.png");echo "Width is: " . $width;echo "Height is: " . $height;echo " The type is: " . $attr;?>
The output result of the above example is:
Width is: 290 Height is: 69 Type is: 3 Attribute: width="290"
<?php$remote_png_url = 'http://www.codercto.com/wp-content/themes/w3cschool.cc/assets/img/logo-domain-green2.png';$img_data = getimagesize($remote_png_url);print_r ($img_data );?>
The output result of the above example is:
Array( [0] => 290 [1] => 69 [2] => 3 [3] => [bits] => 8 [mime] => image/png)
Return result description
Index 0 gives the width of the image in pixels
Index 1 gives the pixel value of the image height
Index 2 gives the type of image and returns a number, where 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF (intel byte order), 8 = TIFF (motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF, 15 = WBMP, 16 = XBM
Index 3 gives a string with width and height, which can be used directly in the HTML <image> tag
The index bits gives the number of bits for each color of the image, in binary format
The index channels gives the channel value of the image. The default for RGB images is 3.
Index mime gives the MIME information of the image. This information can be used to send the correct information in the HTTP Content-type header information, such as: header("Content-type: image/jpeg");