我的 GD 包装器可以很好地处理 JPEG 和 PNG 图像,但是当使用 GIF 图像时,生成的图像会失去透明度。
进一步搜索表明我必须在获取颜色标识符后使用 imagecolortransparent
(设置透明颜色):
imagecolorallocate(资源 $image,int $red,int $green,int $blue)
。
所以问题是:我怎样才能得到原始的透明颜色(RGB)?
最佳答案
假设 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']
希望这有帮助:)
爱所有人:)
关于php - 如何获取GD保存的GIF透明色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8528903/