Home >Backend Development >PHP Tutorial >Imagecopyresized() compressed and saved image is black
<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>
The final saved image is black. The size is normal, but it's completely dark. What's the reason? Thank you
Also, prompt: Warning: imagecopyresized() expects parameter 2 to be resource, string given in F:phpstudyWWWreceive.php on line 10, what went wrong?
<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>
The final saved image is black. The size is normal, but it's completely dark. What's the reason? Thank you
Also, prompt: Warning: imagecopyresized() expects parameter 2 to be resource, string given in F:phpstudyWWWreceive.php on line 10, what went wrong?
You should build an image first, then pass it to the function, and then save it as img, right?
The error message already said that the parameters are illegal