Php methods for retrieving image information

Source: Internet
Author: User
This article mainly introduces the php method for obtaining image information, and analyzes in detail the functions and usage of php in obtaining image information in the form of examples, the user-defined functions are provided to demonstrate how to obtain image information. For more information, see the examples in this article. We will share this with you for your reference. The details are as follows:

The getimagesize () function will determine any GIF, JPG, PNG, SWF, SWC, PSD, TIFF, BMP, IFF, JP2, JPX, JB2, JPC, the size of the XBM or WBMP image file, the size of the returned image, the file type, and a height/width text string that can be used in the IMG mark of a common HTML file.

<? Php/* 1.jpg image of the desired size */$ arr = getimagesize ("1.jpg "); /*** here $ arr is an array type * $ arr [0] indicates the image width * $ arr [1] indicates the image height * $ arr [2] indicates the image's format, including jpg, gif, and png. * $ arr [3] indicates the width and height of the image, the content is width = "xxx" height = "yyy" * // * the output content of the following two lines of code is the same */echo ""; echo "";?>

Obtain the image name, pathinfo () function. you can also obtain the extension of other files.

$a = 'aaaaa.jpg';print_r(pathinfo($a));

Running result:

Array(  [dirname] => .  [basename] => aaaaa.jpg  [extension] => jpg  [filename] => aaaaa)

Supplement: UDFs get image information:

<? Php // The images parameter is the absolute address of the image. function getImagesInfo (images) {img_info = getimagesize (images); switch (img_info [2]) {case 1: imgtype = "gif "; break; case 2: imgtype = "jpg"; break; case 3: imgtype = "png"; break;} img_type = imgtype. "image"; // Obtain the file size img_size = ceil (filesize (img)/1000 ). "k"; new_img_info = array ("width" => img_info [0], // image width "height" => img_info [1], // Image height "type" => img_type, // image type "size" => img_size // image size); return ne W_img_info;}?>

The code is as follows:

Print_r (exif_imagetype ("c:/a"); # you can accurately determine the image type and return the constant of the integer corresponding to the image.


I hope this article will help you with php programming.
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.