PHP 中的 imagecolorat() 函数
phpserver side programmingprogramming更新于 2025/7/6 15:37:17
imagecolorat() 函数获取像素颜色的索引。
语法
imagecolorat( $img, $x, $y )
参数
img:使用 imagecreatetruecolor() 函数创建图像。
x:点的 x 坐标。
y:点的 y 坐标。
返回
imagecolorat() 函数返回颜色索引,失败时返回 FALSE。
示例
以下是示例:
<?php
$img = imagecreatefrompng("http://www.tutorialspoint.com/images/tp-logo-diamond.png");
$rgb = imagecolorat($img, 15, 25);
$colors = imagecolorsforindex($img, $rgb);
var_dump($colors);
?>
输出
输出结果如下:
array(4) { ["red"]=> int(255) ["green"]=> int(255) ["blue"]=> int(255) ["alpha"]=> int(127) }

