array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.imagecolorat.php', 1 => 'imagecolorat', ), 'up' => array ( 0 => 'ref.image.php', 1 => 'GD 和图像处理 函数', ), 'prev' => array ( 0 => 'function.imagecolorallocatealpha.php', 1 => 'imagecolorallocatealpha', ), 'next' => array ( 0 => 'function.imagecolorclosest.php', 1 => 'imagecolorclosest', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/image/functions/imagecolorat.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
imagecolorat — 取得某像素的颜色索引值
返回 image
所指定的图像中指定位置像素的颜色索引值。
如果图像是真彩色图像,此函数以整数返回该点的 RGB 值。用位移加掩码来取得红,绿,蓝各自的值:
返回颜色的索引 或者在失败时返回 false
。
示例 #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) }