PHP + GD:imagetruecolortopalette无法保持透明度

问题描述:

我正在使用GD输出图像,它是使用imagepng的truecolor + alpha通道PNG文件.但是,我也希望能够输出兼容ie6的256色PNG.根据imagetruecolortopalette的官方文档:

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:

对代码进行了修改,除了尽可能保留颜色之外,还保留了最终调色板中尽可能多的alpha通道信息.

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.

但是,我发现此函数的结果根本无法正确保留任何透明性.我使用了这张firefox图片,并在其顶部添加了文字作为测试,所有函数的作用是给我一个白色背景和一个奇怪的深蓝色边框.我知道我不希望保留完整的Alpha通道,但是可以肯定,此功能至少会在透明背景上使用.有什么我想念的吗?我可以采取其他替代方法吗?

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?

我最近遇到了这样的情况-我只能通过使用以下方法来使透明度起作用:

I have recently come across something like this - I could only get the transparency working by using:

imagesavealpha($im, true);
imagecolortransparent($im, imagecolorat($im,0,0));

我知道在所有图像中,左上方的像素都是背景色. 这些分别在imagetruecolortopalette之后和imagepng之后被调用.

I knew that in all the images, the top left pixel would be the background color. These were called after imagetruecolortopalette and before imagepng.