Latest web development tutorials

PHP imagecolorsforindex – 取得某索引的顏色

PHP 圖像處理 PHP圖像處理

imagecolorsforindex — 取得某索引的顏色。

語法

array imagecolorsforindex ( resource $image , int $index )

本函數返回一個具有red,green,blue 和alpha 的鍵名的關聯數組,包含了指定顏色索引的相應的值。

實例

<?php

// 打开一幅图像
$im = imagecreatefrompng('w3big-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
)

相關文章

PHP 圖像處理 PHP圖像處理