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

PHP method to get image details

高洛峰
Release: 2016-10-21 11:06:05
Original
1834 people have browsed it

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;
}
Copy after login


Related labels:
php
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