无论什么哑剧类型,都可以获得图像的高度

时间:2014-12-06 05:27:34

标签: php

我不需要调整此图像的大小,我想要完成的只是收集$ img的实际高度,就像浏览器会解释它一样。我允许用户上传任何图像由于某种原因某些图像不会返回尺寸,只有这个getImageSize();

$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"];

2 个答案:

答案 0 :(得分:1)

更新:您可以使用php函数imagesy()来获取图像资源的高度。 这种方法需要图像资源而不是路径。你必须做这样的事情:它应该适用于所有类型的图像

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

请参阅此处的手册:http://php.net/manual/en/function.imagesy.php http://php.net/manual/en/function.imagecreatefromstring.php

答案 1 :(得分:0)

用这个...... 检查图像类型及其扩展名 然后切换.jpg,png和gif

的大小写

$ im = imagecreatefromjpeg(图片路径); for .jpg

....... imagecreatefrompng(图片路径); for .png

echo imagesy($ im)

我在http://www.dpedit.tk

的表现

我不在我的电脑上。所以我选择了很多类型。