search
Homephp教程PHP开发php getimagesize function - Get image information

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 ] )

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;
?>

The output result of the above example is:

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

Example 2: Remote image file

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

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)

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) !


Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.