【问题标题】:How to get GIF transparency color for saving with GD?如何使用GD保存GIF透明度颜色?
【发布时间】:2012-01-21 16:03:33
【问题描述】:

我的 GD 包装器在处理 JPEG 和 PNG 图像时效果很好,但是当使用 GIF 图像时,生成的图像会失去透明度。

进一步搜索表明我必须在获得颜色标识符后使用imagecolortransparent(设置透明颜色):

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

所以问题是:我怎样才能获得原始的透明颜色(RGB)?

【问题讨论】:

    标签: php image gd gif


    【解决方案1】:

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

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

    应该能够从

    访问实际的 RGB 值
    $actual_transparent_colour['red']
    $actual_transparent_colour['green'] 
    $actual_transparent_colour['blue']
    

    希望这会有所帮助:)

    爱所有人:)

    【讨论】:

      猜你喜欢
      • 2011-07-13
      • 2018-07-07
      • 1970-01-01
      • 1970-01-01
      • 2014-08-05
      • 2020-11-11
      • 1970-01-01
      • 2017-11-19
      • 2015-12-28
      相关资源
      最近更新 更多