RGB 2 HSV color conversion

Conversion from Red/Green/Blue values to Hue/Saturation/Value.

The algorithm in PHP would look like this:

function rgb2Hsv($r, $g, $b) {
 $max = max($r, $g, $b);
 $min = min($r, $g, $b);
 $c = $max - $min;
 $hsv = new stdClass();
 $hsv->v = $max / 255;
 $hsv->s = ($c == 0) ? 0 : ($c / $max);
 if ($c == 0) {
  $h = 0;
 } elseif ($max == $r) {
  $h = fmod((($g - $b) / $c), 6);
 } elseif ($max == $g) {
  $h = (($b - $r) / $c) + 2;
 } elseif ($max == $b) {
  $h = (($r - $g) / $c) + 4;
 }
 $hsv->h = fmod(fmod(60 * $h, 360) + 360, 360);
 return $hsv;
}

For the demo visit: SpyColor.com