I can convert RGB values to HSV with the following code...
$r = $r/255;
$g = $g/255;
$b = $b/255;
$h = 0;
$s = 0;
$v = 0;
$min = min(min($r, $g),$b);
$max = max(max($r, $g),$b);
$r = $max-$min;
$v = $max;
if($r == 0){
$h = 0;
$s = 0;
}
else {
$s = $r / $max;
$hr = ((($max - $r) / 6) + ($r / 2)) / $r;
$hg = ((($max - $g) / 6) + ($r / 2)) / $r;
$hb = ((($max - $b) / 6) + ($r / 2)) / $r;
if ($r == $max) $h = $hb - $hg;
else if($g == $max) $h = (1/3) + $hr - $hb;
else if ($b == $max) $h = (2/3) + $hg - $hr;
if ($h < 0)$h += 1;
if ($h > 1)$h -= 1;
}
But how do you convert HSV to RGB in PHP???
The following is on wikipedia but I don't understand it,
I'm guessing it's pretty obvious
Translation of rolls answer for HSL from C to PHP
ColorJizz allows you to convert from/to many formats. There is a PHP version too.
of course you can, just change the function definitions to php style, change all the variables etc but keep the core code the same, shouldn't take you more than 30 minutes to do that and test it.
This is for the the HSV values in the range
[0,1]
(and giving RGB values in the range[0,1]
, instead of{0, 1, ..., 255}
:Found this post too late, my alternate take on it:
hsv2rgb function PHP
hue: 0-360, sat: 0-100, val: 0-100