Open In App

PHP | ImagickPixel getHSL() function

Last Updated : 23 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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:




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


Output:

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

Program 2:




<?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>");
?>


Output:

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

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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads