📜  PHP | imagickpixel setHSL()函数

📅  最后修改于: 2022-05-13 01:56:37.198000             🧑  作者: Mango

PHP | imagickpixel setHSL()函数

ImagickPixel::setHSL()函数是PHP中的一个内置函数,用于使用标准化的色调、饱和度和亮度值设置 ImagickPixel 对象描述的颜色。

句法:

bool ImagickPixel::setHSL( float $hue, float $saturation, float $luminosity )

参数:此函数接受三个参数,如上所述,如下所述:

  • $hue:它指定了色调的标准化值。
  • $saturation:它指定饱和度的归一化值。
  • $luminosity:它指定了亮度的标准化值。

返回值:此函数在成功时返回 TRUE。

异常:此函数在出错时抛出 ImagickException。

下面给出的程序说明了PHP中的ImagickPixel::setHSL()函数

方案一:

setHSL(0.4, 0.4, 0.4);
  
// Get the HSL of pixel
$HSL = $imagickPixel->getHSL();
print("
".print_r($HSL, true)."
"); ?>

输出:

Array
(
    [hue] => 0.40000158942082
    [saturation] => 0.4000152590219
    [luminosity] => 0.4
)

方案二:

getPixelIterator();
  
// Loop through pixel rows
foreach ($imageIterator as $row => $pixels) {
    // Loop through the pixels in the row
    foreach ($pixels as $column => $pixel) {
  
        // Get the current HSL
        $HSL = $pixel->getHSL();
  
        // Set the HSL and change only hue
        $pixel->setHSL(0.6, $HSL['saturation'], $HSL['luminosity']);
  
    }
  
    // Sync the iterator after each iteration
    $imageIterator->syncIterator();
}
  
header("Content-Type: image/jpg");
echo $imagick;
?>

输出:

参考: https://www. PHP.net/manual/en/imagickpixel.sethsl。 PHP