Skip to content
Related Articles
Open in App
Not now

Related Articles

PHP | ImagickPixel setHSL() function

Improve Article
Save Article
  • Last Updated : 02 Jan, 2020
Improve Article
Save Article

The ImagickPixel::setHSL() function is an inbuilt function in PHP which is used to set the color described by the ImagickPixel object using normalized values for hue, saturation and luminosity.


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

Parameters:This function accepts three parameters as mentioned above and described below:

  • $hue: It specifies the normalized value for hue.
  • $saturation: It specifies the normalized value for saturation.
  • $luminosity: It specifies the normalized value for luminosity.

Return Value: This function returns TRUE on success.

Exceptions: This function throws ImagickException on error.

Below given programs illustrate the ImagickPixel::setHSL() function in PHP:

Program 1:

// Create a new imagickPixel object
$imagickPixel = new ImagickPixel();
// Set the HSL for pixel
$imagickPixel->setHSL(0.4, 0.4, 0.4);
// Get the HSL of pixel
$HSL = $imagickPixel->getHSL();
print("<pre>".print_r($HSL, true)."</pre>");


    [hue] => 0.40000158942082
    [saturation] => 0.4000152590219
    [luminosity] => 0.4

Program 2:

// Create a new imagick object
$imagick = new Imagick(
// Get the pixel iterator to iterate through each pixel
$imageIterator = $imagick->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
header("Content-Type: image/jpg");
echo $imagick;



My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!