简体   繁体   English

PHP GD imagecopy重新采样的糟糕质量

[英]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? 我一直在尝试自己找到一种解决方案,但是我似乎找不到一个解决方案,对GD真的很擅长的人可以提供帮助吗? I can't use imagemagick. 我不能使用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. 您需要使用imagecreatetruecolor()而不是imagecreate()创建画布图像,因为前者创建的画布基于调色板的颜色支持有限。

I presume you are then using imagepng() to save our output the image. 我想您然后使用imagepng()保存我们的输出图像。 The third argument accepted by this function defines the quality of the image, or the compression level (0-9) 此函数接受的第三个参数定义图像的质量或压缩级别(0-9)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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