小白教程
所有教程
关于
Search
172.70.131.84
172.70.131.84
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Php imagecolorclosestalpha”的源代码
本页内容
上一节:
Php_imagecolorclosest
下一节:
Php_imagecolorclosesthwb
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:imagecolorclosestalpha()}}[[Category:PHP GD 图形处理函数参考手册|19]] = PHP imagecolorclosestalpha - 取得与指定的颜色加透明度最接近的颜色的索引 = [[:Category:PHP GD 图形处理函数参考手册]] imagecolorclosestalpha — 取得与指定的颜色加透明度最接近的颜色的索引。 === 语法 === <sample title="" desc="" lang="php" hererun="1"> int imagecolorclosestalpha ( resource $image , int $red , int $green , int $blue , int $alpha ) </sample> 返回图像调色板中与指定的 RGB 值以及 alpha 深度最"接近"的颜色。 === 参数 === * '''image''' 由图像创建函数(例如 imagecreatetruecolor())返回的图像资源。 * '''red''' 红色成分的值。 * '''green''' 绿色成分的值。 * '''blue''' 蓝色成分的值。 * '''alpha''' 一个介于 0 和 127 之间的值。0 表示完全不透明,127 表示完全透明。 颜色参数是介于 0 和 255 之间的整数,或者是介于 0x00 和 0xFF 之间的十六进制数。 === 返回值 === 返回调色板中最接近的颜色的索引。 == 搜索图像中的一组颜色。 <sample title="" desc="" lang="php" hererun="1"> <?php // 从一个图像开始,并将其转换为一个基于调色板的图像 $im = imagecreatefrompng('figures/imagecolorclosest.png'); imagetruecolortopalette($im, false, 255); // 搜索颜色 (RGB) $colors = array( array(254, 145, 154, 50), array(153, 145, 188, 127), array(153, 90, 145, 0), array(255, 137, 92, 84) ); // 循环遍历,查找调色板中最接近的颜色 // 返回搜索次数,搜索的 RGB 和最接近的匹配的 RGB foreach($colors as $id => $rgb) { $result = imagecolorclosestalpha($im, $rgb[0], $rgb[1], $rgb[2], $rgb[3]); $result = imagecolorsforindex($im, $result); $result = "({$result['red']}, {$result['green']}, {$result['blue']}, {$result['alpha']})"; echo "#$id: 搜索 ($rgb[0], $rgb[1], $rgb[2], $rgb[3]); 最接近的匹配: $result。\n"; } imagedestroy($im); ?> </sample> 以上实例的输出类似于: <sample title="" desc="" lang="php" hererun="1"> #0: 搜索 (254, 145, 154, 50); 最接近的匹配: (252, 150, 148, 0)。 #1: 搜索 (153, 145, 188, 127); 最接近的匹配: (148, 150, 196, 0)。 #2: 搜索 (153, 90, 145, 0); 最接近的匹配: (148, 90, 156, 0)。 #3: 搜索 (255, 137, 92, 84); 最接近的匹配: (252, 150, 92, 0)。 </sample> === 相关文章 === * [[php imagecolorexactalpha|imagecolorexactalpha()]] 取得指定的颜色加透明度的索引值。 * [[php imagecolorclosest|imagecolorclosest()]] 取得与指定的颜色最接近的颜色的索引值。 * [[php imagecolorclosesthwb|imagecolorclosesthwb()]] 取得与给定颜色最接近的色度的黑白色的索引。 [[:Category:PHP GD 图形处理函数参考手册]]
返回至“
Php imagecolorclosestalpha
”。
上一节:
Php_imagecolorclosest
下一节:
Php_imagecolorclosesthwb