PHP imagecolorsforindex - Get the color of an index
imagecolorsforindex — Get the color of an index.
Syntax
array imagecolorsforindex ( resource $image , int $index )
This function returns an associative array with keys red, green, blue, and alpha, containing the corresponding values for the specified color index.
Example
<?php
// 打开一幅图像
$im = imagecreatefrompng('example-logo.png');
// 取得一点的颜色
$start_x = 40;
$start_y = 20;
$color_index = imagecolorat($im, $start_x, $start_y);
// 使其可读
$color_tran = imagecolorsforindex($im, $color_index);
// 显示该颜色的值
print_r($color_tran);
?>
The output of the above example is similar to:
Array
(
[red] => 195
[green] => 223
[blue] => 165
[alpha] => 64
)
Related Articles
- imagecolorat()Get the color index value of a pixel.
- imagecolorexact()Get the index value of a specified color.
PHP Image Processing