php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #71074 Wrong Hue value
Submitted: 2015-12-09 11:50 UTC Modified: 2018-11-28 03:20 UTC
From: vadimx at gmail dot com Assigned: danack (profile)
Status: Not a bug Package: imagick (PECL)
PHP Version: 5.5.30 OS: Windows 7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: vadimx at gmail dot com
New email:
PHP Version: OS:

 

 [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
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-09 15:11 UTC] danack@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: danack
 [2015-12-09 15:11 UTC] 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 15:35 UTC] danack@php.net
Reported upstream as: https://github.com/ImageMagick/ImageMagick/issues/64
 [2015-12-29 21:14 UTC] danack@php.net
-Type: Bug +Type: Documentation Problem
 [2015-12-29 21:14 UTC] 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
 [2018-11-28 03:20 UTC] danack@php.net
-Status: Assigned +Status: Not a bug
 [2018-11-28 03:20 UTC] danack@php.net
Forgot to change the status before.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 10:01:28 2024 UTC