PHP imagecolorsforindex - 取得某索引的顏色
imagecolorsforindex — 取得某索引的顏色。
語法
array imagecolorsforindex ( resource $image , int $index )
本函數返回一個具有 red,green,blue 和 alpha 的鍵名的關聯數組,包含了指定顏色索引的相應的值。
實例
<?php
// 打開一幅圖像
$im = imagecreatefrompng('zaixian-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);
?>
以上實例的輸出類似於:
Array
(
[red] => 195
[green] => 223
[blue] => 165
[alpha] => 64
)
相關文章
- imagecolorat() 取得某像素的顏色索引值。
- imagecolorexact() 取得指定顏色的索引值。

PHP 圖像處理