简体   繁体   中英

PHP GD imagecopyresampled horrible quality

Not sure why it looks so bad, but when I copy an image over another image, it looks extremely terrible, like it lost almost all its colors for some reason.

$img = imagecreate(240, 140);    
$wall = imagecreatefrompng($src);
imagecopyresampled($img, $wall, 0, 0, 40, 340, 240, 140, 240, 140);

I've been trying to find a solution myself but I can't seem to find one, anybody really good with GD that can help? I can't use imagemagick.

You need to create your canvas image with imagecreatetruecolor() rather than imagecreate() as the former creates a palette based canvas with limited colour support.

I presume you are then using imagepng() to save our output the image. The third argument accepted by this function defines the quality of the image, or the compression level (0-9)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM