php - 如何获取GD保存的GIF透明色?

标签 php image gd gif

我的 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/

相关文章:

PHP 和 mySQL - 多用户应用程序方法

php - 从 JavaScript 调用 php 脚本

Html/Css 图像无法在 IE 中正确显示并调整大小(左而不是右)

PHP:如何将 "near white"表示为颜色?

php - 如何使用 PHP 的 GD 库对图像执行缝线雕刻?

php - 在 Wordpress 页面的下拉列表中显示来自数据库 mySQL 的数据

php - $facebook->getSession() 在示例代码中返回 null。那样行吗?

php - 将图像解析为数据[任何语言]

CSS:Firefox/Internet Explorer 中 flexbox 的图像缩放问题

php - 合并两个PNG透明图像