PHP imagecolorsforindex - Get the color of an index

PHP 图像处理PHP Image Processing

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

PHP 图像处理PHP Image Processing

Other Extensions