当前位置:Gxlcms > PHP教程 > php缩略图的有关问题

php缩略图的有关问题

时间:2021-07-01 10:21:17 帮助过:4人阅读

php缩略图的问题
以下是我的代码:

1.2.https://www.gxlcms.com/$ef='index\images\m_1307414811439.jpg';
3.$bs="";
4.$rr=getimagesize(https://www.gxlcms.com/$ef);
5.$new=imagecreatetruecolor(300,300);
6.imagecopyresized($new,$bs,0,0,0,0,300,300,$rr[0],$rr[1]);
7.header("content-type:image/jpeg");
8.imagejpeg($new);
9.?>

出现的问题是6,7行报错,还有乱码

Warning: imagecopyresized(): supplied argument is not a valid Image resource in D:\PHP\r.php on line 6

Warning: Cannot modify header information - headers already sent by (output started at D:\PHP\r.php:6) in D:\PHP\r.php on line 7
????JFIF??>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ??C    $.' ",#(7),01444'9=82<.342??C  2!!22222222222222222222222222222222222222222222222222??,,"?? ???}!1AQa"q2亼?#B绷R佯$3br? %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz儎厗噲墛挀敃枟槞殺¥ウЖ┆渤吹斗腹郝媚牌侨墒矣哉肿刭卺忏溴骁栝犟蝮趱鲼??? ???w!1AQaq"2?B憽绷 #3R?br? $4?%?&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz們剠唶垑姃摂晼棙櫄ⅲぅΗī炒刀犯购旅呐魄壬室釉罩棕仝忏溴骁栝牝篝貊鼬?? ??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(?

------解决方案--------------------
imagecopyresized函数的前两个参数要求是图形对象变量,不是文件名路径字符串之类的东西,你第2个参数传的是$bs,然而你前面把它赋值为字符串内容,所以出错
我随便修了下代码,你看着思考吧


https://www.gxlcms.com/$ef='1.jpg';
$bs=imagecreatefromjpeg(https://www.gxlcms.com/$ef);
$rr=getimagesize(https://www.gxlcms.com/$ef);
$new=imagecreatetruecolor(300,300);
imagecopyresized($new,$bs,0,0,0,0,300,300,$rr[0],$rr[1]);
header("content-type:image/jpeg");
imagejpeg($new);

人气教程排行