函数名:imagecolorsforindex()
适用版本:PHP 4, PHP 5, PHP 7
用法:imagecolorsforindex() 函数用于获取图像指定索引的颜色信息。
语法:bool imagecolorsforindex ( resource $image , int $index , array &$color )
参数:
返回值:成功时返回 true,失败时返回 false。
示例:
// 创建一个图像资源
$image = imagecreatefromjpeg('image.jpg');
// 获取索引为 10 的颜色信息
$index = 10;
$color = array();
if (imagecolorsforindex($image, $index, $color)) {
// 输出颜色信息
echo "Red: " . $color['red'] . "<br>";
echo "Green: " . $color['green'] . "<br>";
echo "Blue: " . $color['blue'] . "<br>";
} else {
echo "获取颜色信息失败";
}
// 销毁图像资源
imagedestroy($image);
注意事项: