Advertisement
khAldr0g0

contrast

Dec 10th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1.     <?php
  2. class Effects{
  3.  
  4.     private $numColors;
  5.     private $image;
  6.     private $imageW=0,$imageH=0;
  7.     //$r=$g=$b=array();
  8.    
  9.     function __construct(& $img){
  10.         imagetruecolortopalette($img,true,256);
  11.         $this->numColors=imageColorsTotal($img);
  12.         $this->image=$img;
  13.         $this->imageW=imagesx($img);
  14.         $this->imageH=imagesy($img);
  15.     }
  16.    
  17.     function contrast($adjust){
  18.         $nc=$this->numColors;
  19.         $im=$this->image;
  20.         $iw=$this->imageW; $ih=$this->imageH;
  21.         $adjust=pow(($adjust+100)/100,2);
  22.  
  23.          $newimg = @imageCreateTrueColor($iw, $ih);
  24.         for($x=0; $x < $iw; $x++){
  25.             for($y=0; $y < $ih; $y++){
  26.                 $idx = imageColorAt($im, $x, $y);
  27.                 list($r,$g,$b,$a) = array_values(imageColorsForIndex($im, $idx));
  28.  
  29.                 $r /=255; $r -=5; $r *=$adjust; $r +=5; $r *=255;
  30.                 if($r>255) $r=255;
  31.  
  32.                 $g /=255; $g -=5; $g *=$adjust; $g +=5; $g *=255;
  33.                 if($g>255) $g=255;
  34.  
  35.                 $b /=255; $b -=5; $b *=$adjust; $b +=5; $b *=255;
  36.                 if($b>255) $b=255;
  37.  
  38.                 $col = imageColorAllocate($newimg, $r,$g,$b);
  39.                 imageSetPixel($newimg,$x,$y,$col);
  40.             }
  41.         }
  42.         return $newimg;
  43.     }
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement