#RGB color saturation change: what is missing here?

Below is the concept for a brightness / saturation change program with brightness() and saturation() .

 function brightness($colorstr, $steps) { ... return sprintf("%02x%02x%02x", $r, $g, $b); } function saturation(){ ... return sprintf("%02x%02x%02x", $r, $g, $b); } 

Are there any existing easy-to-use mods on the Internet to complement this ane, do the following:

 $color2 = saturation($color,-10); /* less staurated*/ $color3 = saturation($color,+10); /* more staurated*/ 
+2
source share
2 answers

Saturation and brightness cannot be handled the same way (it can be argued that you incorrectly control the brightness using this code, but probably close enough). See This RGB Question for HSV in PHP for converting color to HSV value, then you can change the saturation (S value). Then convert back using PHP HSV to RGB answer to this question.

+2
source

I cannot answer this code, but I am a wikipedia article on color and color that describes this theory very well.

+1
source

All Articles