Imagecopyresized() compressed and saved image is black

WBOY
Release: 2016-08-18 09:16:28
Original
2145 people have browsed it

<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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!