PHP Verification Upload Image size _php tutorial

Source: Internet
Author: User
getimagesize function Get image size (PHP 4, PHP 5)

Array getimagesize (string filename [, array &imageinfo])//note ¥Imageinfo in use does not need to be in front of &.

Description
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.

Attention:
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. Support for TIFF was added by PHP 4.2.0, PHP 5.3 added support for icon

Attention:
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.

Attention:
This function does not require the GD image library.

Returns an array with four cells. Index 0 contains the pixel value of the image width, and index 1 contains the pixel value of the image height. Index 2 is a marker 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,17 = ico,18 = COUNT. These tags correspond to the newly added IMAGETYPE constants of PHP 4.3.0. Index 3 is a text string with the content "height=" yyy "width=" xxx ", which can be used directly with the IMG tag.

Example getimagesize (file)
List ($width, $height, $type, $attr) = getimagesize ("img/flag.jpg");
echo "width={$width}, height={$height}, type={$type}, attr={$attr}";
?>
URL support is added by PHP 4.0.5.

Example GetImageSize (URL)
$size = getimagesize ("Http://www.example.com/gifs/logo.gif");

If the file name has space in it, encode it properly
$size = getimagesize ("Http://www.example.com/gifs/logo.gif");

?>
For JPG images, more than two indexes are returned: channels and bits. Channels has a value of 3 for the RGB image and a value of 4 for the CMYK image. BITS is the number of bits per color.

from PHP 4.3.0, bits and channels exist for other image types as well. But these values can confuse people. For example, GIF always uses 3 channel for each pixel, but for animated GIFs, the number of bits per pixel cannot be computed by the global color table.

Some formats may not contain images or contain multiple images. In this case, getimagesize () may not be used to accurately determine the size of the image. At this point, getimagesize () returns 0 as the width and height.

from PHP 4.3.0, getimagesize () also returns an additional parameter mime that conforms to the MIME type of the image. This information can be used to send the correct information in the HTTP content-type header message:

Example getimagesize () and MIME type
$size = getimagesize ($filename);
$FP =fopen ($filename, "RB");
if ($size && $fp) {
Header ("Content-type: {$size [' MIME ']}");
Fpassthru ($FP);
Exit
} else {
Error
}
?>
The optional imageinfo parameter allows you to extract some extended information from the image file. Currently, this will return a different JPG APP identifier with an associative array. Some programs use these APP identifiers to embed text information in an image. One very common is the iptc»http://www.iptc.org/information embedded in the APP13 identity. You can use the Iptcparse () function to parse a binary APP13 identity into readable information.

Example getimagesize () returns IPTC
$size = getimagesize ("testimg.jpg", $info);
if (Isset ($info ["APP13"])) {
$IPTC = Iptcparse ($info ["APP13"]);
Var_dump ($IPTC);
}
?>

http://www.bkjia.com/PHPjc/775951.html www.bkjia.com true http://www.bkjia.com/PHPjc/775951.html techarticle getimagesize function Gets the image size (PHP 4, PHP 5) array getimagesize (string filename [, array imageinfo])//note ¥imageinfo when used Not in front of the need. Description ...

  • Related Article

    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.