php getimagesize function - Get Image Information
The getimagesize() function is used to get the image size and related information. On success it returns an array; on failure it returns FALSE and generates an E_WARNING level error message.
Syntax format:
array getimagesize ( string $filename [, array &$imageinfo ] )
The getimagesize() function determines the size of any GIF, JPG, PNG, SWF, SWC, PSD, TIFF, BMP, IFF, JP2, JPX, JB2, JPC, XBM, or WBMP image file and returns the image dimensions, file type, and image height and width.
Example 1: Local image file
The output of the above example is:
宽度为:290
高度为:69
类型为:3
属性:width="290" height="69"
Example 2: Remote image file
The output of the above example is:
Array
(
[0] => 290
[1] => 69
[2] => 3
[3] => width="290" height="69"
[bits] => 8
[mime] => image/png
)
Return value description
- Index 0 gives the pixel value of the image width
- Index 1 gives the pixel value of the image height
- Index 2 gives the image type, returned as 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 of width and height that can be used directly in HTML's
tag
- Index bits gives the number of bits for each color of the image, in binary format
- Index channels gives the channel value of the image; RGB images default to 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, e.g.: header("Content-type: image/jpeg");
PHP Image Processing