Home > Backend Development > PHP Tutorial > A function to comprehensively obtain image information_PHP tutorial

A function to comprehensively obtain image information_PHP tutorial

WBOY
Release: 2016-07-13 17:34:16
Original
814 people have browsed it


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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508498.htmlTechArticle?php functiongetImageInfo($img){//$img is the absolute path of the image file$img_info=getimagesize($ img); switch($img_info[2]){ case1: $imgtype=GIF; break; case2: $imgtype=JPG; break; case3:...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template