PHP 中的 imagecolorexact() 函数


imagecolorexact() 函数获取指定颜色的索引。

语法

imagecolorexact ( $img, $red, $green, $blue )

参数

  • img: 使用 imagecreatetruecolor() 创建的图像资源。

  • red: 红色颜色组件

  • green: 绿色颜色组件

  • blue: 蓝色颜色组件

返回

imagecolorexact() 函数返回调色板中指定颜色的索引,如果颜色不存在,则返回 -1。

示例

以下是一个示例

 在线演示

<?php
   $img =    imagecreatefrompng('https://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 )

更新于: 31-Dec-2019

53 次浏览

开启你的 职业生涯

通过完成本课程,获得认证

立即开始
广告
© . All rights reserved.