PHP imagecolorsforindex - Get the color of an index

PHP imagecolorsforindex - Get the color of an index PHP image processing

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

PHP imagecolorsforindex - Get the color of an index PHP image processing