php getimagesize
getimagesize是讀取圖片相關信息,返回一個具有四個單元的數組。索引 0 包含圖像寬度的像素值,索引 1 包含圖像高度的像素值。索引 2 是圖像類型的標
<?php
$size = getimagesize($filename);
$fp = fopen($filename, "rb");
if ($size && $fp) {
header("Content-type: {$size['mime']}");
fpassthru($fp);
exit;
} else {
// error
}
?>
#2 getimagesize() example
<?php
list($width, $height, $type, $attr) = getimagesize("img/flag.jpg");
echo "<img src="img/flag.jpg" $attr alt="getimagesize() example" />";
?>
Example #3 getimagesize (URL)
<?php
$size = getimagesize("http://www.example.com/gifs/logo.gif");
$size = getimagesize("http://www.example.com/gifs/lo%20go.gif");
?>
Example #4 getimagesize() returning IPTC
<?php
$size = getimagesize("testimg.jpg", $info);
if (isset($info["APP13"])) {
$iptc = iptcparse($info["APP13"]);
var_dump($iptc);
}
?>