PHP | ImagickPixel setHSL() function
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.
Syntax:
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:
<?php
$imagickPixel = new ImagickPixel();
$imagickPixel ->setHSL(0.4, 0.4, 0.4);
$HSL = $imagickPixel ->getHSL();
print ( "<pre>" .print_r( $HSL , true). "</pre>" );
?>
|
Output:
Array
(
[hue] => 0.40000158942082
[saturation] => 0.4000152590219
[luminosity] => 0.4
)
Program 2:
<?php
$imagick = new Imagick(
$imageIterator = $imagick ->getPixelIterator();
foreach ( $imageIterator as $row => $pixels ) {
foreach ( $pixels as $column => $pixel ) {
$HSL = $pixel ->getHSL();
$pixel ->setHSL(0.6, $HSL [ 'saturation' ], $HSL [ 'luminosity' ]);
}
$imageIterator ->syncIterator();
}
header( "Content-Type: image/jpg" );
echo $imagick ;
?>
|
Output:
Reference: https://www.php.net/manual/en/imagickpixel.sethsl.php
Last Updated :
02 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...