(PHP 4, PHP 5, PHP 7, PHP 8)
imagecolorat — 取得某像素的颜色索引值
返回 image 所指定的图像中指定位置像素的颜色索引值。
如果图像是真彩色图像,此函数以整数返回该点的 RGB 值。用位移加掩码来取得红,绿,蓝各自的值:
返回颜色的索引 或者在失败时返回 false。
| 版本 | 说明 |
|---|---|
| 8.0.0 |
image 现在需要 GdImage 实例;之前需要有效的 gd resource。
|
示例 #1 访问不同的 RGB 值
<?php
$im = imagecreatefrompng("php.png");
$rgb = imagecolorat($im, 10, 15);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
var_dump($r, $g, $b);
?>
以上例程的输出类似于:
int(119) int(123) int(180)
示例 #2 使用 imagecolorsforindex() 获取可读的 RGB 值
<?php
$im = imagecreatefrompng("php.png");
$rgb = imagecolorat($im, 10, 15);
$colors = imagecolorsforindex($im, $rgb);
var_dump($colors);
?>
以上例程的输出类似于:
array(4) {
["red"]=>
int(119)
["green"]=>
int(123)
["blue"]=>
int(180)
["alpha"]=>
int(127)
}