|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-12-09 11:50 UTC] vadimx at gmail dot com
Description:
------------
ImagickPixel:getHSL, has wrong Hue value
Test script:
---------------
$p = new ImagickPixel();
$p->setColor('rgb(158,146,130)');
print_r($p->getHSL());
Expected result:
----------------
Array
(
[hue] => 0.34285714285714
[saturation] => 0.12612612612613
[luminosity] => 0.56470588235294
)
Actual result:
--------------
Array
(
[hue] => 0.095238095238095
[saturation] => 0.12612612612613
[luminosity] => 0.56470588235294
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Tue Jan 13 16:00:02 2026 UTC |
I was going to ask you how you were calculating that the values were 'wrong'. However I realised that doing the conversion RGB -> HSL -> RGB gives different RGB color than the starting one.....e.g. the code below outputs: InputColor: rgb(158, 146, 130) FinalColor: rgb(158.00, 141.00, 130.00) This is very likely going to be an issue with the underlying ImageMagick library, which I will need to investigate and report upstream. $inputColor = "rgb(158, 146, 130)"; $fromRGB = new ImagickPixel($inputColor); $hsl = $fromRGB->getHSL(); $hslString = sprintf( "hsl(%.4f, %.4f, %.4f)", $hsl['hue'] * 255, $hsl['saturation'] * 255, $hsl['luminosity'] * 255 ); $fromHSL = new ImagickPixel($hslString); $outputColorArray = $fromHSL->getColor(false); $finalColor = sprintf( "rgb(%.2f, %.2f, %.2f)", $outputColorArray['r'], $outputColorArray['g'], $outputColorArray['b'] ); echo "hslString is $hslString\n"; echo "InputColor: ".$inputColor."\n"; echo "FinalColor: ".$finalColor."\n";