Heim  >  Artikel  >  Backend-Entwicklung  >  imagecopyresized()压缩保存的图像是黑色的

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

WBOY
WBOYOriginal
2016-08-18 09:16:282145Durchsuche

<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吧?
报错信息已经说了参数不合法

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn