PHP 中的 imagecolorexact() 函数
phpserver side programmingprogramming更新于 2025/7/6 8:52:17
imagecolorexact() 函数获取指定颜色的索引。
语法
imagecolorexact ( $img, $red, $green, $blue )
参数
img:使用 imagecreatetruecolor() 创建的图像资源。
red:红色成分
green:绿色成分
blue:蓝色成分
返回
imagecolorexact() 函数返回调色板中指定颜色的索引,如果颜色不存在,则返回 -1存在。
示例
以下是示例:
<?php
$img = imagecreatefrompng('https://www.tutorialspoint.com/assets/videos/courses/67/images/course_67_image.png');
$colors = Array();
$colors[] = imagecolorexact($img, 30, 90, 50);
$colors[] = imagecolorexact($img, 80, 120, 100);
$colors[] = imagecolorexact($img, 25, 80, 50);
print_r($colors);
imagedestroy($img);
?>
输出
输出结果如下:
Array ( [0] => 1989170 [1] => 5273700 [2] => 1658930 )

