How to get GIF transparency color for saving with GD?

左心房为你撑大大i 提交于 2019-12-10 18:54:26

问题


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

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).

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


回答1:


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);
}

Should be able to access the actual RGB values from

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

Hope this helps :)

Love to all :)



来源:https://stackoverflow.com/questions/8528903/how-to-get-gif-transparency-color-for-saving-with-gd

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!