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.