Home  >  Article  >  php教程  >  php getimagesize

php getimagesize

WBOY
WBOYOriginal
2016-06-13 11:22:521231browse

php getimagesize

getimagesize是读取图片相关信息,返回一个具有四个单元的数组。索引 0 包含图像宽度的像素值,索引 1 包含图像高度的像素值。索引 2 是图像类型的标

$size = getimagesize($filename);
$fp = fopen($filename, "rb");
if ($size && $fp) {
    header("Content-type: {$size['mime']}");
    fpassthru($fp);
    exit;
} else {
    // error
}
?>


#2 getimagesize() example

list($width, $height, $type, $attr) = getimagesize("img/flag.jpg");
echo "getimagesize() example";
?>

Example #3 getimagesize (URL)

$size = getimagesize("http://www.example.com/gifs/logo.gif");
$size = getimagesize("http://www.example.com/gifs/lo%20go.gif");
?>

Example #4 getimagesize() returning IPTC

$size = getimagesize("testimg.jpg", $info);
if (isset($info["APP13"])) {
    $iptc = iptcparse($info["APP13"]);
    var_dump($iptc);
}
?>


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