首页  >  文章  >  后端开发  >  imagecopyresized()压缩保存的图像是黑色的

imagecopyresized()压缩保存的图像是黑色的

WBOY
WBOY原创
2016-08-18 09:16:282143浏览

<code><?php move_uploaded_file($_FILES['upload']['tmp_name'],'x1.jpg');
$img='x1.jpg';
$thumbs=imagecreatetruecolor(500,500);
$imgs=getimagesize($img);
$width=500;
$height=500;
imagecopyresized($thumbs,$img,0,0,0,0,$width,$height,$img[0],$img[1]);
imagejpeg($thumbs,'xxxx.jpg');
?></code>

最后保存出的图像是黑色的。大小正常,就是一片漆黑,是什么原因呢?谢谢

而且,提示:Warning: imagecopyresized() expects parameter 2 to be resource, string given in F:phpstudyWWWreceive.php on line 10,哪里出问题了?

回复内容:

<code><?php move_uploaded_file($_FILES['upload']['tmp_name'],'x1.jpg');
$img='x1.jpg';
$thumbs=imagecreatetruecolor(500,500);
$imgs=getimagesize($img);
$width=500;
$height=500;
imagecopyresized($thumbs,$img,0,0,0,0,$width,$height,$img[0],$img[1]);
imagejpeg($thumbs,'xxxx.jpg');
?></code>

最后保存出的图像是黑色的。大小正常,就是一片漆黑,是什么原因呢?谢谢

而且,提示:Warning: imagecopyresized() expects parameter 2 to be resource, string given in F:phpstudyWWWreceive.php on line 10,哪里出问题了?

应该是要先构建一个图片,然后传给函数,然后保存为img吧?
报错信息已经说了参数不合法

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn