Home > php教程 > PHP开发 > php getimagesize function - Get image information

php getimagesize function - Get image information

黄舟
Release: 2016-12-28 12:00:03
Original
1412 people have browsed it

The getimagesize() function is used to obtain the image size and related information. It returns an array if successful. If it fails, it returns FALSE and generates an E_WARNING level error message.

Syntax format:

array getimagesize ( string $filename [, array &$imageinfo ] )
Copy after login

getimagesize() function will measure any GIF, JPG, PNG, SWF, SWC, PSD, TIFF, BMP, IFF, JP2, JPX, JB2, JPC, XBM Or the size of a WBMP image file and returns the dimensions of the image as well as the file type and image height and width.

Example 1: Local image file

<?php
list($width, $height, $type, $attr) = getimagesize("runoob-logo.png");
echo "宽度为:" . $width;
echo "高度为:" . $height;
echo "类型为:" . $attr;
?>
Copy after login

The output result of the above example is:

宽度为:290
高度为:69
类型为:3
属性:width="290" height="69"
Copy after login

Example 2: Remote image file

<?php
$remote_png_url = &#39; 
$img_data = getimagesize($remote_png_url);print_r($img_data );?>
Copy after login

The output result of the above example is: :

Array(
    [0] => 290
    [1] => 69
    [2] => 3
    [3] => width="290" height="69"
    [bits] => 8
    [mime] => image/png)
Copy after login

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 image and 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 is given is a string of width and height, which can be directly used in the tag of HTML

The index bits gives the number of bits for each color of the image, in binary format

Index channels gives the channel value of the image. The default for RGB images is 3

. Index mime gives the MIME information of the image. This information can be used to send the correct information in the HTTP Content-type header. , such as: header("Content-type: image/jpeg");

The above is the php getimagesize function - the content of obtaining image information. For more related content, please pay attention to the PHP Chinese website (www.php.cn) !


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template