PHP | ImagickPixel getHSL() function

The ImagickPixel::getHSL() function is an inbuilt function in PHP which is used to get the normalized HSL color described by the ImagickPixel object, with each being floating-point numbers between 0 and 1. HSL stands for hue, saturation, and luminosity. In general, hue decides what color is of the pixel whereas saturation decides the intensity of color further luminosity decides whether the color is dull or bright.

Syntax:

array ImagickPixel::getHSL( void )

Parameters:This function doesn’t accept any parameter.



Return Value: This function returns an array value containing the HSL values.

Exceptions: This function throws ImagickException on error.

Below given programs illustrate the ImagickPixel::getHSL() function in PHP:
Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// Create a new imagickPixel object
$imagickPixel = new ImagickPixel('#d4a62a');
  
// Get the HSL
$hsl = $imagickPixel->getHSL();
print("<pre>".print_r($hsl, true)."</pre>");
?>

chevron_right


Output:

Array
(
    [hue] => 0.12156862745098
    [saturation] => 0.66929133858268
    [luminosity] => 0.49803921568627
)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// Create a new imagickPixel object
$imagick = new Imagick(
   
// Get the image histogram
$histogramElements = $imagick->getImageHistogram();
   
// Get the 300th pixel
$getPixel = $histogramElements[300];
  
// Get the HSL
$hsl = $getPixel->getHSL();
  
print("<pre>".print_r($hsl, true)."</pre>");
?>

chevron_right


Output:

Array
(
    [hue] => 0.54583333333333
    [saturation] => 0.29850746268657
    [luminosity] => 0.26274509803922
)

Reference: https://www.php.net/manual/en/imagickpixel.gethsl.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.