开发者

How to get the rgb colors from an already allocated color in PHP GD

开发者 https://www.devze.com 2023-01-12 05:14 出处:网络
How would you get the colors from an allocated color something like... $col = imagecolorallocate($im, 255, 50, 5);

How would you get the colors from an allocated color something like...

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

$rgb = rgbfromallocate($col);
开发者_StackOverflow中文版print $rgb['r'];//255
print $rgb['g'];//50
print $rgb['b'];//5


Maybe imagecolorsforindex() is what you're looking for?

For example:

// $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
0

精彩评论

暂无评论...
验证码 换一张
取 消