我不需要調整此圖像的大小,我所要完成的所有工作就是收集$ img的實際高度,就像瀏覽器解釋它一樣。我允許用戶上傳任何圖像出於某種原因某些圖像不會返回維度,只是這個getImageSize();獲取圖像的高度,無論是什麼MIME類型
$img = $_GET['img'];
unction remoteImage($url){
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
curl_setopt($ch, CURLOPT_RANGE, "0-10240");
$fn = $img;
$raw = curl_exec($ch);
$result = array();
if(file_exists($fn)){
unlink($fn);
}
if ($raw !== false) {
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($status == 200 || $status == 206) {
$result["w"] = 0;
$result["h"] = 0;
$fp = fopen($fn, 'x');
fwrite($fp, $raw);
fclose($fp);
$size = getImageSize($fn);
if ($size===false) {
// Cannot get file size information
} else {
// Return width and height
list($result["w"], $result["h"]) = $size;
}
}
}
curl_close ($ch);
return $result;
}
$outputheight = $result["h"];
當我嘗試使用getImageSize()時,返回空白。 – Nato 2014-12-06 05:33:13
方法不是getImageSize()它是getimagesize() – 2014-12-06 05:34:36
我一直在閱讀這個和基於圖像的創建方式,圖像可能埋葬在代碼中的實際高度和寬度取決於使用什麼樣的圖像創建最終的副本。我不知道這是否屬實。我想知道是否有一種方法來預加載圖像並使用DOM提取它? – Nato 2014-12-06 05:37:12