php getimagesize function - Get image information
getimagesize () function is used to get the image size and related information, the successful return of an array, then failed to return FALSE and generate an error of level E_WARNING message.
Syntax:
array getimagesize ( string $filename [, array &$imageinfo ] )
getimagesize () function will be measured any GIF, JPG, PNG, SWF, SWC, PSD, TIFF, BMP, IFF, JP2, JPX, JB2, JPC, XBM, or WBMP image file size and return the image size and file type and image height and width.
Example 1: Local image file
<?php list($width, $height, $type, $attr) = getimagesize("w3big-logo.png"); echo "宽度为:" . $width; echo "高度为:" . $height; echo "类型为:" . $attr; ?>
The above example output is:
宽度为:290 高度为:69 类型为:3 属性:width="290" height="69"
Example 2: Remote File Photos
<?php $remote_png_url = '../wp-content/themes/w3cschool.cc/assets/img/logo-domain-green2.png'; $img_data = getimagesize($remote_png_url); print_r($img_data ); ?>
The above example output is:
Array ( [0] => 290 [1] => 69 [2] => 3 [3] => width="290" height="69" [bits] => 8 [mime] => image/png )
(S) Description
- Index zero gives the width of the image pixel values
- Index gives the image height 1 pixel values
- Index 2 shows the type of image, returns the 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
- 3 index is given a width and height of the string can be used directly in the HTML <image> tag
- Index is the number of bits is given for each color image, binary format
- Index channels gives the channel value of the image, RGB image default is 3
- Mime MIME index gives the information of the image, this information can be used in the HTTP Content-type header information to send the correct information, such as: header ( "Content-type: image / jpeg");