2014-12-06 28 views
2

我不需要調整此圖像的大小,我所要完成的所有工作就是收集$ 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"]; 

回答

0

更新:你可以使用PHP函數imagesy()獲得的圖像資源的高度。 這種方法需要圖像資源不path.you必須做這樣的事情:http://php.net/manual/en/function.imagesy.php http://php.net/manual/en/function.imagecreatefromstring.php

+0

當我嘗試使用getImageSize()時,返回空白。 – Nato 2014-12-06 05:33:13

+0

方法不是getImageSize()它是getimagesize() – 2014-12-06 05:34:36

+0

我一直在閱讀這個和基於圖像的創建方式,圖像可能埋葬在代碼中的實際高度和寬度取決於使用什麼樣的圖像創建最終的副本。我不知道這是否屬實。我想知道是否有一種方法來預加載圖像並使用DOM提取它? – Nato 2014-12-06 05:37:12

0

使用本... 檢查:應該爲所有類型的圖像

$x="resultproces.gif"; 
$im = imagecreatefromstring(file_get_contents($x)); 
echo imagesy($im); 

在這裏看到工作手冊圖片類型及其擴展名 然後切換爲.jpg,png和gif格

$ im = imagecreatefromjpeg(image to path); for .jpg

....... imagecreatefrompng(path to image);爲.png格式

回聲imagesy($ IM)

這就是我所做的http://www.dpedit.tk

我不是在我的電腦。所以我輸入很多。