Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function saturate($adjust){
- $img=$this->image;
- $nc=imageColorsTotal($img);
- $s=$adjust;
- //$lumR= 0.2125; $lumG= 0.7154; $lumB= 0.0721;
- $lumR = 0.3086; $lumG= 0.6094; $lumB= 0.0820;
- $d=1.0-$s;
- $sr=$d*$lumR; $sg=$d*$lumG; $sb=$d*$lumB;
- $a0=$sr+$s; $a1=$sg+$s; $a2=$sb+$s;
- $ar=array([$a0,$sr,$sr,0,0],[$sg,$a1,$sg,0,0],[$sb,$sb,$a2,0,0],[0,0,0,1.0,0]);
- $result=function ($r,$g,$b,$a) use($ar){
- for($i=0; $i<=4; $i++){
- $colors[$i] =($ar[0][$i]*$r)+($ar[1][$i]*$g)+($ar[2][$i]*$b)+($ar[3][$i]*$a);
- }
- return $colors;
- };
- $clamp=function($val)
- {
- return (($val>255)?255 : (($val<0)?0 :$val));
- };
- for($x=0; $x<$nc; $x++){
- list($r,$g,$b,$a)=array_values(imageColorsForIndex($img,$x));
- $color=$result($r/255,$g/255,$b/255,$a);
- $nr=$clamp($color[0]*255);
- $ng=$clamp($color[1]*255);
- $nb=$clamp($color[2]*255);
- $na=$color[3];
- imageColorSet($img,$x,$nr,$ng,$nb,$na);
- }
- return $img;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement