如何获得GIF透明色以便用GD保存? [英] How to get GIF transparency color for saving with GD?

查看:78
本文介绍了如何获得GIF透明色以便用GD保存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的GD包装器与JPEG和PNG图像的魅力相似,但是当使用GIF图像时,生成的图像会失去透明度。

My GD wrapper works like charm with JPEG and PNG images, however when using GIF image the resulting image loses transparency.

进一步搜索建议我必须使用<$获取颜色标识符后,c $ c> imagecolortransparent (设置透明色):

Further search suggests i have to use imagecolortransparent (sets the transparent color) after getting color identifier with:

imagecolorallocate(resource $ image ,int $ red,int $ green,int $ blue)

所以问题是:我怎么能得到原始的透明色(RGB)?

So question is: how can i get original transparecy color (RGB)?

推荐答案

假设GIF图像被加载到资源$ image ...尝试以下

Assuming that the GIF image is loaded into resource $image... try the following

$index_of_transparent_colour = imagecolortransparent($image);
if($index_of_transparent_colour != -1) {
    $actual_transparent_colour = imagecolorsforindex($image,$index_of_transparent_colour);
}

应该可以从

$actual_transparent_colour['red']
$actual_transparent_colour['green'] 
$actual_transparent_colour['blue']

希望这有助于:)

爱所有人: )

这篇关于如何获得GIF透明色以便用GD保存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆