Home >Backend Development >PHP Tutorial >Imagecopyresized() compressed and saved image is black

Imagecopyresized() compressed and saved image is black

WBOY
WBOYOriginal
2016-08-18 09:16:282225browse

<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?

Reply content:

<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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn