首頁  >  文章  >  後端開發  >  imagecopyresized()壓縮儲存的影像是黑色的

imagecopyresized()壓縮儲存的影像是黑色的

WBOY
WBOY原創
2016-08-18 09:16:282145瀏覽

<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