imagecolorsforindex

(PHP 4, PHP 5, PHP 7, PHP 8)

imagecolorsforindex取得某索引的顏色

說明

imagecolorsforindex(resource $image, int $index): array

本函數(shù)返回一個(gè)具有 red,green,blue 和 alpha 的鍵名的關(guān)聯(lián)數(shù)組,包含了指定顏色索引的相應(yīng)的值。

示例 #1 imagecolorsforindex() 例子

<?php

// 打開一幅圖像
$im imagecreatefrompng('nexen.png');

// 取得一點(diǎn)的顏色
$start_x 40;
$start_y 50;
$color_index imagecolorat($im$start_x$start_y);

// 使其可讀
$color_tran imagecolorsforindex($im$color_index);

// 顯示該顏色的值
echo '<pre>';
print_r($color_tran);
echo 
'</pre>';

?>

本例將輸出:

Array
(
    [red] => 226
    [green] => 222
    [blue] => 252
    [alpha] => 0
)

參見 imagecolorat()imagecolorexact()。