The getimagesize () function will determine the size of any gif, jpg, png, swf, swc, psd, tiff, bmp, iff, jp2, jpx, jb2, jpc, xbm or wbmp image file and return the size of the image and the file type and a Can be used for height/width text strings in img tags in normal html files.

<?php/* 1.jpg for the picture i want to get its size * /
$arr=getimagesize ("1.jpg");
 * Here $arr is an array type
 * $arr [0] is the width of the image
 * $arr [1] is the height of the image
 * $arr [2] is the format of the image,Including jpg, gif and png etc.
 * $arr [3] is the width and height of the image,The content is width="xxx" height="yyy"
 * /
/* The output of the following two lines of code are the same * /
echo "<img src =" 1.jpg "$arr [3] />";
echo "<img src =" 1.jpg "width =" $arr [0] "height =" $arr [1] "/>";

Get the picture name,pathinfo () function, this can also get the extension of other files.

print_r (pathinfo ($a));

operation result:

  [dirname] =>.
  [basename] =>aaaaa.jpg
  [extension] =>jpg
  [filename] =>aaaaa

Added:Custom function to get picture information:

//The parameter images is the absolute address of the picture
function getimagesinfo (images) {
img_info=getimagesize (images);
switch (img_info [2]) {
case 1:
case 2:
case 3:
img_type=imgtype. "image";
//Get 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 new_img_info;
print_r (exif_imagetype ("c:/a"));#You can accurately determine the type of the image.
  • Previous C # complete example of adding a watermark to a picture
  • Next Detailed explanation of JavaScript based on object-oriented object creation (1)