Posted By

michaJlS on 02/10/11


Tagged

RGB hsv


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

alexteg


HSV2RGB


 / Published in: PHP
 

I don't remember where I have found it.

  1. function HSV_TO_RGB(array $hsv) {
  2. list($H,$S,$V) = $hsv;
  3. //1
  4. $H *= 6;
  5. //2
  6. $I = floor($H);
  7. $F = $H - $I;
  8. //3
  9. $M = $V * (1 - $S);
  10. $N = $V * (1 - $S * $F);
  11. $K = $V * (1 - $S * (1 - $F));
  12. //4
  13. switch ($I) {
  14. case 0:
  15. list($R,$G,$B) = array($V,$K,$M);
  16. break;
  17. case 1:
  18. list($R,$G,$B) = array($N,$V,$M);
  19. break;
  20. case 2:
  21. list($R,$G,$B) = array($M,$V,$K);
  22. break;
  23. case 3:
  24. list($R,$G,$B) = array($M,$N,$V);
  25. break;
  26. case 4:
  27. list($R,$G,$B) = array($K,$M,$V);
  28. break;
  29. case 5:
  30. case 6: //for when $H=1 is given
  31. list($R,$G,$B) = array($V,$M,$N);
  32. break;
  33. }
  34. return array($R, $G, $B);
  35. }

Report this snippet  

You need to login to post a comment.