首页 > 技术文章 > php获取图片宽高等属性

kwishly 2013-12-03 10:13 原文

<?php
function getImageInfo($image) {
    $imageInfo = getimagesize($image);
    if ($imageInfo !== FALSE) {
        $imageType = strtolower(substr(image_type_to_extension($imageInfo[2]), 1));
        $imageSize = filesize($image);
        $info = array(
            "width" => $imageInfo[0],
            "height" => $imageInfo[1],
            "type" => $imageType,
            "size" => $imageSize,
            "mime" => $imageInfo['mime']
        );
        return $info;
    } else {
        return FALSE;
    }
}
$info = getImageInfo('test.jpg');
var_dump($info);
?>

推荐阅读