/ Published in: PHP
i found it somewhere...
Expand |
Embed | Plain Text
function RGB_TO_HSV ($R, $G, $B) // RGB Values:Number 0-255 { // HSV Results:Number 0-1 $var_R = ($R / 255); $var_G = ($G / 255); $var_B = ($B / 255); $del_Max = $var_Max - $var_Min; $V = $var_Max; if ($del_Max == 0) { $H = 0; $S = 0; } else { $S = $del_Max / $var_Max; $del_R = ( ( ( $max - $var_R ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max; $del_G = ( ( ( $max - $var_G ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max; $del_B = ( ( ( $max - $var_B ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max; if ($var_R == $var_Max) $H = $del_B - $del_G; else if ($var_G == $var_Max) $H = ( 1 / 3 ) + $del_R - $del_B; else if ($var_B == $var_Max) $H = ( 2 / 3 ) + $del_G - $del_R; if (H<0) $H++; if (H>1) $H--; } $HSL['H'] = $H; $HSL['S'] = $S; $HSL['V'] = $V; return $HSL; }
Comments
Subscribe to comments
You need to login to post a comment.

It contains at least two errors: $max in lines 24-26 is undefined. My guess is that should be: $var_Max (which i think is a terrible name...) . Furthermore H in lines 32 and 33 should be $H. regards, Michael