PHP imagecolorsforindex - Get the color of an index
Imagecolorsforindex - Get the color of an index.
Grammar
array imagecolorsforindex ( resource $image , int $index )
This function returns an associated array of key names with red, green, blue, and alpha, containing the corresponding values for the specified color index.
Instance
<?php
// 打开一幅图像
$im = imagecreatefrompng('youj-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 examples is similar to:
Array ( [red] => 195 [green] => 223 [blue] => 165 [alpha] => 64 )
Related articles
- Imagecolorat() obtains the color index value of a pixel.
- Imagecolorexact() obtains the index value of the specified color.