Doc #71074 [Asn->Nab]: Wrong Hue value

From: Date: Wed, 28 Nov 2018 03:20:05 +0000
Subject: Doc #71074 [Asn->Nab]: Wrong Hue value
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-16177@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71074&edit=1 ID: 71074 Updated by: danack@php.net Reported by: vadimx at gmail dot com Summary: Wrong Hue value -Status: Assigned +Status: Not a bug Type: Documentation Problem Package: imagick Operating System: Windows 7 PHP Version: 5.5.30 Assigned To: danack Block user comment: N Private report: N New Comment: Forgot to change the status before. Previous Comments: ------------------------------------------------------------------------ [2015-12-29 21:14:02] danack@php.net So, it's not a bug. The values are all normalized 0 - 1.0. Most HSL converters don't normalize the hue to that range, and instead have 0-360 or 0-3.6. To get your expected result you need to multiply by 3.6 ------------------------------------------------------------------------ [2015-12-09 15:35:33] danack@php.net Reported upstream as: https://github.com/ImageMagick/ImageMagick/issues/64 ------------------------------------------------------------------------ [2015-12-09 15:11:00] danack@php.net 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"; ------------------------------------------------------------------------ [2015-12-09 11:50:18] 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 ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71074&edit=1

« previous php.doc.bugs (#16177) next »