如何从PHP GD中已经分配的颜色中获取rgb颜色

时间:2010-08-20 14:46:34

标签: php colors gd rgb

如何从分配的颜色中获取颜色 类似......

$col = imagecolorallocate($im, 255, 50, 5);
//A fake function - rgbfromallocate (that I wish I knew)

$rgb = rgbfromallocate($col);
print $rgb['r'];//255
print $rgb['g'];//50
print $rgb['b'];//5

1 个答案:

答案 0 :(得分:5)

也许imagecolorsforindex()正是您要找的?

例如:

// $img is an image
$color = imagecolorallocate($img, 255, 50, 5);

$rgb = imagecolorsforindex($img, $color);
print $rgb['red']; // 255
print $rgb['green']; // 50
print $rgb['blue']; // 5
print $rgb['alpha']; // 0, but if the image uses the alpha channel,
// this would have a value of up to 127, which is fully transparent