Home  >  Article  >  Backend Development  >  PHP method to get image details

PHP method to get image details

高洛峰
高洛峰Original
2016-10-21 11:06:051788browse

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;
}


Statement:
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