PHP | imagecolorclosestalpha()函数
imagecolorclosestalpha()函数是PHP中的一个内置函数,用于获取给定图像中具有 alpha 值的最接近颜色的索引。此函数返回最接近指定 RGB 值和 alpha 级别的图像调色板中颜色的索引。 alpha 值表示图像的透明度。
句法:
int imagecolorclosestalpha ( $image, $red, $green, $blue, $alpha )
参数:该函数接受上面提到的五个参数,如下所述:
- $image:它由图像创建函数之一返回,例如 imagecreatetruecolor()。它用于创建图像的大小。
- $red:此参数用于设置红色分量的值。
- $green:此参数用于设置绿色分量的值。
- $blue:此参数用于设置蓝色分量的值。
- $alpha:此参数用于设置图像的透明度。 $alpha 的值介于 0 到 127 之间,其中 0 表示完全不透明,而 127 表示完全透明。
返回值:此函数返回调色板中最接近颜色的索引。
下面的程序说明了PHP中的imagecolorclosestalpha()函数:
方案一:
PHP
PHP
$rgb)
{
$output = imagecolorclosestalpha($image, $rgb[0],
$rgb[1], $rgb[2], $rgb[3]);
$output = imagecolorsforindex($image, $output);
$output = "({$output['red']}, {$output['green']},
{$output['blue']}, {$output['alpha']})";
echo "Given color: ($rgb[0], $rgb[1], $rgb[2], $rgb[3])
=> Closest match: $output
";
}
imagedestroy($image);
?>
输出:
Closest match: (100, 58, 108, 0)
方案二:
PHP
$rgb)
{
$output = imagecolorclosestalpha($image, $rgb[0],
$rgb[1], $rgb[2], $rgb[3]);
$output = imagecolorsforindex($image, $output);
$output = "({$output['red']}, {$output['green']},
{$output['blue']}, {$output['alpha']})";
echo "Given color: ($rgb[0], $rgb[1], $rgb[2], $rgb[3])
=> Closest match: $output
";
}
imagedestroy($image);
?>
输出:
Given color: (155, 40, 200, 50) => Closest match: (100, 58, 108, 0)
Given color: (235, 205, 188, 127) => Closest match: (100, 58, 108, 0)
Given color: (135, 0, 132, 0) => Closest match: (100, 58, 108, 0)
相关文章:
- PHP | imagecharup()函数
- PHP | imagedashedline()函数
参考: 函数 : PHP 。 PHP