The use of getimagesize functions in PHP

Source: Internet
Author: User

PHP gets picture information getimagesize,php self-function. There are many ways to get the type of a picture, and the function is only one of the methods.

The getimagesize () function will determine any GIF,JPG,PNG,SWF,SWC,PSD,TIFF,BMP,IFF,JP2,JPX,JB2,JPC,XBM or WBMP The size of the image file and returns the size of the image as well as the file type and a height/width text string that can be used in an IMG tag in an ordinary HTML file.

If the image specified by filename cannot be accessed or is not a valid image, GetImageSize () returns false and produces an e_warning level error.

$info getimagesize (' HTTP://TP1.SINAIMG.CN/3270140212/180/40025391519/1 '); Print_r ($info); Array (    [0] = [    1] = [2    ] = 2    [3] = = width= " "Height=    " (+ 8    = 3    = image/jpeg)

Attention:

1. Support for JPC,JP2,JPX,JB2,XBM and WBMP is available from PHP 4.3.2. Support for SWC is available from PHP 4.3.0. The support for TIFF is added by PHP 4.2.0.

Note:jpeg 2000 support is added by PHP 4.3.2. Note that JPC and JP2 can have different color depth components. In this case, the value of "bits" is the highest bit depth encountered. Additionally, the JP2 file may contain multiple JPEG 2000 code streams, in which case getimagesize () returns the value of the first code stream encountered in the top level of this file.

2, this function does not need GD image Library

The function getimagesize () is used to obtain image size and related information, which is a string representation of an image resource. An image resource can be a resource that can be obtained, such as a server picture (the latter URL picture), or an image resource uploaded by a user form.
An example is as follows:
$array = getimagesize ("images/flower_1.jpg");
Print_r ($array);

The return value of the function is an array of the following:
Array
(
[0] = 350
[1] = 318
[2] = 2
[3] = = width= "350″height=" 318″
[Bits] = 8
[Channels] = 3
[MIME] = Image/jpeg
)
Index 0 gives the pixel value of the width of the image;
Index 1 gives the pixel value of the height of the image;
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 or Der), 9 = jpc,10 = jp2,11 = jpx,12 = jb2,13 = swc,14 = iff,15 = wbmp,16 = XBM;
Index 3 gives a width and height of the string, can be directly used in HTML <image> tags;
Index bits gives the number of bits per color of the image, and the binary;
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")

Reprint: http://www.kviews.net/php/216

http://www.libaqiang.com/?p=7001

The use of getimagesize functions in PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.