Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function convert_RGA_HSV ($colour) {
- $r = substr($colour,1,2);
- $g = substr($colour,3,2);
- $b = substr($colour,5,2);
- $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;
- }
- return array($h, $s, $v);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement