Latest web development tutorials

PHP imagecolorat – 取得某像素的顏色索引值

PHP 圖像處理 PHP圖像處理

imagecolorat — 取得某像素的顏色索引值。

語法

int imagecolorat ( resource $image , int $x , int $y )

返回image 所指定的圖形中指定位置像素的顏色索引值。

如果PHP 編譯時加上了GD 庫2.0 或更高的版本並且圖像是真彩色圖像,則本函數以整數返回該點的RGB 值。 用移位加掩碼來取得紅,綠,藍各自成分的值。

實例

取得各自的RGB 值。

<?php
$im = ImageCreateFromPng("w3big-logo.png");
$rgb = ImageColorAt($im, 100, 25);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
?>

相關文章

PHP 圖像處理 PHP圖像處理