- The getimagesize () function is used to obtain information such as image size, type, and so on.
- The Imagesx () function is used to get the width of the image.
- The Imagesy () function is used to get the height of the image.
GetImageSize ()
The getimagesize () function is used to obtain the image size and related information, successfully returns an array, and fails to return false and produces an e_warning level error message.
Grammar:
Array getimagesize (string filename)
Example:
<?php$array = getimagesize ("images/flower_1.jpg");p Rint_r ($array);? >
The browser appears as follows:
Array ( [0] = [1] = 318 [2] = 2 [3] = width= "height=" 318 " [bits] = 8 [Channels] + 3 [MIME] = image/jpeg)
Return result 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 type of the image, which 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 of width and height that can be used directly in HTML <image> tags
- Index bits gives the number of bits per color of the image, in binary format
- Index channels gives the channel value of the image, the RGB image by default is 3
- The index MIME gives the MIME information of the image, which can be used to send the correct information in the HTTP Content-type header information, such as:
Header ("Content-type:image/jpeg");
Tips
If you want to run an example of image processing in this tutorial on your own computer, download the pictures in the tutorial to the local images folder for backup:
Http://www.5idev.com/Public/Images/article/flower_1.jpg
Http://www.5idev.com/Public/Images/article/logo_mark.gif
Imagesx ()
The Imagesx () function is used to get the width of the image, in pixels, and the return value as an integral type.
Grammar:
int Imagesx (resource image)
Parameters are image resources returned by functions such as Imagecreatetruecolor (), Imagecreatefromjpeg (), and so on.
Imagesy ()
The Imagesy () function is used to obtain the height, syntax, and usage of the image with Imagesx ().
Grammar:
int Imagesy (resource image)
Example:
<?php$img = Imagecreatefromjpeg ("images/flower_1.jpg"); echo "Image width:", Imagesx ($img), "<br/>"; echo "image height:", Imagesy ($img);? >
Browser output:
Image width: 350 Image height: 318
Other:
The fastest speed gets the length and width of all the pictures on the page
http://bbs.csdn.net/topics/380257438
PHP Get image information getimagesize function