Home >Backend Development >PHP Tutorial >PHP method to get image details
PHP method to get image details
First we pass a parameter $filename of the image path, which is an absolute path
First we get the image size through the getimagesize method
//获取图片详细信息 function getImageInfo($filename){ //$img为图像文件绝对路径 $size = getimagesize($filename); switch ($img_info[2]) { case 1: $imgtype = "GIF"; break; case 2: $imgtype = "JPG"; break; case 3: $imgtype = "PNG"; break; } $img_type = $imgtype . "图像"; $img_size = ceil(filesize($filename) / 1000) . "k"; //获取文件大小 $imgInfo = array( "width" => $size[0], "height" => $size[1], "type" => $img_type, "size" => $img_size ); return $imgInfo; }