PHP + GD:imagetruecolortopalette 不保持透明度
我正在使用 GD 输出一个图像,该图像是使用 imagepng 的 truecolor+alpha 通道 PNG 文件。但是,我也希望能够输出兼容 ie6 的 256 色 PNG。根据 imagetruecolortopalette 的官方文档:
代码已被修改,除了尽可能保留颜色之外,还可以在结果调色板中保留尽可能多的 Alpha 通道信息。
然而,我发现这个函数的结果根本没有正确地保持任何透明度。我使用 这张 Firefox 图像 并将文本叠加在其顶部作为测试,并且所有该函数所做的是给我一个白色背景和一个奇怪的深蓝色边框。我知道我不能希望保留完整的 Alpha 通道,但可以肯定的是,这个函数至少会在透明背景上出现。我有什么遗漏的吗?我可以采取其他方法吗?
I am using GD to output an image that is a truecolor+alpha channel PNG file using imagepng just fine. However, I would like to have the ability to also output an ie6-compatible 256-color PNG as well. According to the official documentation for imagetruecolortopalette:
The code has been modified to preserve as much alpha channel information as possible in the resulting palette, in addition to preserving colors as well as possible.
However, I am finding that the results of this function do not properly preserve any transparency at all. I used this firefox image with text superimposed on top of it as a test, and all the function did was give me a white background and a weird dark blue border. I know that I can't hope to preserve the full alpha channel, but surely this function would at least pick up on the transparent background. Is there something I'm missing? Are there any alternative approaches that I can take?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我最近遇到过这样的事情 - 我只能通过使用来获得透明度:
我知道在所有图像中,左上角的像素将是背景颜色。
这些在 imagetruecolortopalette 之后和 imagepng 之前被称为。
I have recently come across something like this - I could only get the transparency working by using:
I knew that in all the images, the top left pixel would be the background color.
These were called after imagetruecolortopalette and before imagepng.
我能够通过在
imagetruecolortopalette
之前保存像素,然后替换为
as来保持透明度
I was able to keep trasparency by saving pixels before
imagetruecolortopalette
withthen replacing with
as
看看 php 文档中的 imagesavealpha - 我认为这个就是您正在寻找的。
take a look at imagesavealpha in the php-documentation - i think this is what you are looking for.