Home >Backend Development >PHP Tutorial >A function to comprehensively obtain image information_PHP tutorial
function getImageInfo($img) { //$img is the absolute path of the image file
$img_info = getimagesize($img);
switch ($img_info[2]) {
case 1:
$imgtype = "GIF";
break;
case 2:
$imgtype = "JPG";
break;
case 3:
$imgtype = "PNG";
break;
}
$img_type = $imgtype."image";
$img_size = ceil(filesize($img)/1000)."k"; //Get the file size
$new_img_info = array (
"width"=>$img_info[0],
"height"=>$img_info[1],
"type"=>$img_type
"size"=>$img_size
}
return $new_img_info;
}
?>
It’s very simple and everyone should understand it.