PHP function for obtaining image size: getimagesize

Source: Internet
Author: User
Getimagesize (PHP4, PHP5) getimagesize & nbsp; & mdash; & nbsp; returns the image size description array & nbsp; getimagesize & nbsp; (& nbsp; string & nbsp; $ filename & nbsp; [, & nbsp; array & nbsp; & am getimagesize

(PHP 4, PHP 5)

Getimagesize? -? Get Image size

Description array? Getimagesize? (? String? $filename? [,? Array? &$imageinfo?] )

Getimagesize ()? The 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 the size of the returned image, the file type, and a common? HTML? File?IMG? The height/width text string in the flag.

If not?filename? The specified image or the image is not valid ,?Getimagesize ()? Will return?FALSE? And generate one?E_WARNING? Level error.

Note:

Right? JPC, JP2, JPX, JB2, XBM? And? WBMP? Is available from PHP 4.3.2. Right? SWC? Is available from PHP 4.3.0. Right? TIFF? Is added in PHP 4.2.0.

Note:? Added in PHP 4.3.2 for JPEG 2000. Note that JPC and JP2 can have different color depth components. In this case, the value of "bits" is the highest bit depth encountered. In addition, the JP2 file may contain multiple JPEG 2000 code streams. in this case ,?Getimagesize ()? Returns the value of the first code stream encountered in the top layer of the file.

Note:? This function does not require the GD Image Library.

Returns an array with four units. Index 0 contains the pixel value of the image width, and index 1 contains the pixel value of the image height. Index 2 is the mark of the image type: 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. These tags correspond to the newly added IMAGETYPE constant in PHP 4.3.0. Index 3 is a text string with the content "height =" yyy "width =" xxx "and can be directly used for IMG marking.

Example #1 getimagesize (file)

 

The URL can be added in PHP 4.0.5.

Example #2 getimagesize (URL)

 

For? JPG? The image will return two more indexes:Channels? And?Bits.Channels? The value of an RGB image is 3, and that of a CMYK image is 4.Bits? Is the number of digits of each color.

Since PHP 4.3.0,Bits? And?Channels? Other image types also exist. However, these values may confuse people. For example, GIF? Three channels are always used for each pixel, but for animation? GIF? The number of bits in each pixel cannot be calculated from the global color table.

Some formats may not contain images or contain multiple images. In this case ,?Getimagesize ()? It may not be used to accurately determine the image size. Now?Getimagesize ()? Returns zero as the width and height.

Since PHP 4.3.0 ,?Getimagesize ()? Will return additional parameters?MimeThe MIME type of the image. This information can be used to send the correct information in the HTTP Content-type header:

Example #3 getimagesize () and MIME type

 

Optional?imageinfo? Parameters allow extraction of some extended information from image files. Currently, this will return different? JPG? APP Id. Some programs use these APP identifiers to embed text information in the image. Which of the following is very common? IPTC??? Http://www.iptc.org /? Information. Available? Iptcparse ()? Function to parse the binary APP13 identifier into readable information.

Example #4 getimagesize () returns IPTC

 

 

See? Image_type_to_mime_type (),? Exif_imagetype (),? Exif_read_data ()? And? Exif_thumbnail ().

Parameters
filename
This parameter specifies the file you wish to retrieve information about. It can reference a local file or (configuration permitting) a remote file using one of the supported streams.
imageinfo
This optional parameter allows you to extract some extended information from the image file. Currently, this will return the different? JPG? APP markers as an associative array. Some programs use these APP markers to embed text information in images. A very common one is to embed ??? IPTC? Information in the APP13 marker. You can use? Iptcparse ()? Function to parse the binary APP13 marker into something readable.
Return value

Returns an array with 7 elements.

Index 0 and 1 contains respectively the width and the height of the image.

Note:

Some formats may contain no image or may contain multiple images. In these cases ,?Getimagesize ()? Might not be able to properly determine the image size .?Getimagesize ()? Will return zero for width and height in these cases.

Index 2 is one of?IMAGETYPE_XXX? Constants indicating the type of the image.

Index 3 is a text string with the correct?Height = "yyy" width = "xxx"? String that can be used directly in? IMG? Tag.

Mime? Is the correspondant MIME type of the image. This information can be used to deliver images with the correct HTTP?Content-type? Header:

Example #5?Getimagesize ()? And MIME types

 

Channels? Will be 3 for RGB pictures and 4 for CMYK pictures.

Bits? Is the number of bits for each color.

For some image types, the presence?Channels? And?Bits? Values can be a bit confusing. As an example ,? GIF? Always uses 3 channels per pixel, but the number of bits per pixel cannot be calculated for an animated? GIF? With a global color table.

On failure ,?FALSE? Is returned.

Error/exception

If accessing?filename? Image is impossible, or if it isn't a valid picture ,?Getimagesize ()? Will generate an error of level?E_WARNING. On read error,Getimagesize ()? Will generate an error of level?E_NOTICE.

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.