2014-12-06 24 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

我不是在我的电脑。所以我输入很多。