Chinaunix

标题: 关于imagesx(): 和imagesy(): 的一些迷惑~~特地前来请教~~ [打印本页]

作者: 浪迹天    时间: 2005-07-17 22:39
标题: 关于imagesx(): 和imagesy(): 的一些迷惑~~特地前来请教~~
偶学PHP不久,最近在暑假写点东西~遇到些问题,前来请教,希望大家帮忙解决~~

我在写一个像册的时候在用到imagesx(): 这些函数的时候遇到一些问题,问题描述如下:
Warning: imagesx(): supplied argument is not a valid Image resource in E:\www\xpc2\cfg.php on line 331

Warning: imagesy(): supplied argument is not a valid Image resource in E:\www\xpc2\cfg.php on line 332

Warning: imagedestroy(): supplied argument is not a valid Image resource in E:\www\xpc2\cfg.php on line 333

我在cfg.php on 331-333的代码估计大家已经猜出来了,就是:
        $iminfo[0]=imagesx($im);    //照片宽
        $iminfo[1]=imagesy($im);    //照片高
        imagedestroy($im);
我本来是想取得照片的宽和高的,结果就出项上面问题~~希望解决~~
作者: phphp    时间: 2005-07-18 11:16
标题: 关于imagesx(): 和imagesy(): 的一些迷惑~~特地前来请教~~
关键东东没给
$im 不能使用
作者: 浪迹天    时间: 2005-07-19 04:56
标题: 关于imagesx(): 和imagesy(): 的一些迷惑~~特地前来请教~~
主要就是用来分情况处理上传的图片的各种格式的,就是下面这个函数的~~

function createthumb($src,$otype,$album)
{
        global $thumbdir;

        if($otype!=".bmp"
        {
        $picname=basename($src);
        $type=strtolower($otype);
        $im_des=$thumbdir.$album."_".$picname.".jpg";
        if($otype==".jpg"||$type==".jpeg"
                $im=@imagecreatefromjpeg($src);
        if($otype==".gif"
                $im=@imagecreatefromgif($src);
        if($otype==".png"
                $im=@imagecreatefrompng($src);

        $width=@imagesx($im);
        $height=@imagesy($im);
        if($width>;100||$height>;90)
        {
        @$ratio=$height/$width;

        if($ratio<0.9)
        {
                $newwidth=100;
                @$newheight=$height*(100/$width);
        }
        else
        {
                $newheight="90";
                $newwidth=$width*(90/$height);
        }

        $im_s=@imagecreatetruecolor($newwidth,$newheight);
        @imagecopyresized($im_s,$im,0,0,0,0,$newwidth,$newheight,$width,$height);
        @imagejpeg($im_s,$im_des,70);
        @chmod($im_des,0777);
        @imagedestroy($im);
        }
        else
                copy($src,$thumbdir.$album."_".$picname.".jpg";
        }
}

麻烦大家还是帮忙我看看~~
还有大家有没有更加好的办法来处理图片格式不一样的问题,希望得到帮助~~~




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2