PHP | imagecolorclosesthwb()函数

这个 imagecolorclosesthwb() 函数是PHP中的一个内置函数,用于获取给定图像中的色调、白色和黑色的索引。此函数返回一个整数值,其中包含最接近给定颜色的色调、白色和黑色的颜色索引。

null

语法:

int imagecolorclosesthwb ( $image, $red, $green, $blue )

参数: 该函数接受上述四个参数,如下所述:

  • $image: 它由一个图像创建函数返回,例如imagecreatetruecolor()。它用于创建图像的大小。
  • $red: 此参数用于设置红色分量的值。
  • $green: 此参数用于设置绿色分量的值。
  • $blue: 此参数用于设置蓝色组件的值。

返回值: 此函数返回一个整数值,其中颜色色调、白色和黑色的索引最接近图像中的给定颜色。

下面的程序说明了 imagecolorclosesthwb() 函数。

项目1:

<?php
// Create new image from given URL
$image = imagecreatefromgif(
// Display the index of color
echo 'Hue White and Blackness closest color index: '
. imagecolorclosesthwb( $image , 5, 165, 10);
imagedestroy( $image );
?>


输出:

Hue White and Blackness closest color index: 42

项目2:

<?php
// Create new image from given URL
$image = imagecreatefromgif(
// Array contains rgb color value
$color = array (
array (7, 150, 0),
array (53, 190, 255),
array (255, 165, 54)
);
// Loop to find closest HWB color
foreach ( $color as $id => $rgb )
{
echo 'Hue White and Blackness closest color index: '
. imagecolorclosesthwb( $image , $rgb [0], $rgb [1], $rgb [2]) . "<br>" ;
}
imagedestroy( $image );
?>


输出:

Hue White and Blackness closest color index: 42
Hue White and Blackness closest color index: 101
Hue White and Blackness closest color index: 186

相关文章:

参考: http://php.net/manual/en/function.imagecolorclosesthwb.php

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享