我有以下程序以快速方式計算圖像高度和寬度,比較getImageSize(); PHP函數。原因?遠程圖像將需要下載到您的服務器,然後它會被本地讀取的PHP。快速計算圖像高度和寬度
<?php
function getimagesize($image_url){
$handle = fopen ($image_url, "rb");
$contents = "";
if ($handle) {
do {
$count += 1;
$data = fread($handle, 8192);
if (strlen($data) == 0) {
break;
}
$contents .= $data;
} while(true);
} else { return false; }
fclose ($handle);
$im = ImageCreateFromString($contents);
if (!$im) { return false; }
$gis[0] = ImageSX($im);
$gis[1] = ImageSY($im);
// array member 3 is used below to keep with current getimagesize standards
$gis[3] = "width={$gis[0]} height={$gis[1]}";
ImageDestroy($im);
return $gis;
}
$image_url = "http://xample.com/4.jpg";
$get = getimagesize($image_url);
print $get;
?>
但執行此PHP代碼後,我收到以下錯誤
Fatal error: Cannot redeclare getimagesize() in C:\wamp\www\test\CheckWH.php on line 25
DONE,是我不好! – SSK