Okay, I have written a function that should convert HSL color value to RGB. I have rewritten it in PHP according to this script: http://www.easyrgb.com/index.php?X=MATH&H=19#text19
This is what I have:
function HSL2RGB($h, $s, $l){
function hue2rgb($v1, $v2, $vH){
$sH = $vH;
if($vH<0) $sH += 1;
if($vH>1) $sH -= 1;
if((6*$sH)<1) return $v1+($v2-$v1)*6*$sH;
if((2*$sH)<1) return $v2;
if((3*$sH)<2) return $v1+($v2-$v1)*((2/3)-$sH)*6;
return $v1;
}
$h *= (5/18);
$s /= 100;
$l /= 100;
$r=$g=$b=NULL;
if($s==0){
$r=$l*255;
$g=$l*255;
$b=$l*255;
}else{
if($l<0.5)
$var_2 = $l*(1+$s);
else
$var_2 = ($l+$s)-($s*$l);
$var_1 = 2*$l-$var_2;
$r = 255*hue2rgb($var_1, $var_2, $h+(1/3));
$g = 255*hue2rgb($var_1, $var_2, $h);
$b = 255*hue2rgb($var_1, $var_2, $h-(1/3));
}
return array('r'=>$r,'g'=>$g,'b'=>$b);
}
var_dump(HSL2RGB(196.4, 100, 59.8));
The output of this script:
array(3) {
["r"]=>
float(49.98)
["g"]=>
float(49.98)
["b"]=>
float(49.98)
}
The correct output is R: 50, G:199, B:255
. I adapted it perfectly from the reference script from easyrgb.com
. I just can't figure out why it isn't working. Any help would be awesome. Thanks.