PHP GD 中的 GIF 图像质量较差
我正在开发一个水印脚本,在 PNG 和 JPG 图像上效果很好,但在 gif 图像上效果不太好。 我使用 PHP 和 GD
下面你可以看到水印质量的差异。
有人知道如何改进这个吗?
对于 gif 版本,我使用的是
$image = imagecreatefromgif($source_file);
imagecopymerge($image, $watermark, $x, $y, 0, 0, $water_width, $water_height, 65);
imagegif($image, $source_file);
gif 图像 = 质量差 gif 图像 http://img2.pict.com/fd/ 46/00/1471179/0/gif.gif
jpg 图像 = 好 jpg 图片 http://img2.pict.com/82/ a1/5a/1471181/0/jpg.jpg
I have a watermark script I am working on, the results are good on PNG and on JPG images however a gif image, not so good. I am using PHP and GD
Below you can see the difference in quality of the watermark.
Anyone know how to improve this?
For the gif version I am using
$image = imagecreatefromgif($source_file);
imagecopymerge($image, $watermark, $x, $y, 0, 0, $water_width, $water_height, 65);
imagegif($image, $source_file);
gif image = bad quality
gif image http://img2.pict.com/fd/46/00/1471179/0/gif.gif
jpg image = good
jpg image http://img2.pict.com/82/a1/5a/1471181/0/jpg.jpg
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
GIF 图像有一个固定的调色板,最多可包含 256 种颜色。 这里的问题可能是您插入的图像使用了目标图像中不可用的颜色。
我从未尝试过这个,但可能值得一试。 您可以尝试先将 gif 图像转换为真彩色图像,然后添加水印,然后再将其转换回 gif。
尝试一下,看看是否有所不同。
还有一些调色板操作函数可能会有所帮助:
我不确定你会如何应用它们,但我猜有一些您可以采取哪些措施来改善结果。
GIF images have a fixed palette that can contain a maximum of 256 colors. The issue here is probably that the image your inserting uses colors that isn't available in the target image.
I have never tried this, but it might be worth a shot. You could try converting the gif image to a true color image first, then do the watermarking and after that converting it back to gif.
Try it and see if it makes a difference.
There's also a couple of palette manipulation functions available that might help:
I'm not sure how you would apply them, but I'm guessing that there's a few things you could do to improve the results.
GIF 仅支持 256 色的调色板。 因此,水印图像的颜色必须映射到该调色板。 这导致它们以与以前不同的颜色进行渲染和保存。 由于调色板很小,一般情况下不建议使用 GIF 格式的照片。
GIF only supports a color palette of 256 colors. Therefore, the colors of your watermark image have to be mapped to this palette. This caused them to be rendered and saved with different colors than before. Due to this small palette, GIF is not recommended for photos in general, anyways.
GIF 图像永远不会看起来很棒,因为调色板有 256 种颜色。 正如 MrMage 所说,颜色映射会导致图像真实颜色的严重近似。 你最好使用 PNG,它们确实支持透明度。
GIF images will never look great, as the colour palette is 256 colours. As MrMage says, colour mapping causes a severe approximation of the true colours of the image. You are better off with PNGs, they do support transparency.