PHP Get image information getimagesize function

Source: Internet
Author: User

    • 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
    1. Index 0 gives the pixel value of the image width
    2. Index 1 gives the pixel value of the image height
    3. 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
    4. Index 3 gives a string of width and height that can be used directly in HTML <image> tags
    5. Index bits gives the number of bits per color of the image, in binary format
    6. Index channels gives the channel value of the image, the RGB image by default is 3
    7. 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

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.