Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Effects{
- private $numColors;
- private $image;
- private $imageW=0,$imageH=0;
- //$r=$g=$b=array();
- function __construct(& $img){
- imagetruecolortopalette($img,true,256);
- $this->numColors=imageColorsTotal($img);
- $this->image=$img;
- $this->imageW=imagesx($img);
- $this->imageH=imagesy($img);
- }
- function contrast($adjust){
- $nc=$this->numColors;
- $im=$this->image;
- $iw=$this->imageW; $ih=$this->imageH;
- $adjust=pow(($adjust+100)/100,2);
- $newimg = @imageCreateTrueColor($iw, $ih);
- for($x=0; $x < $iw; $x++){
- for($y=0; $y < $ih; $y++){
- $idx = imageColorAt($im, $x, $y);
- list($r,$g,$b,$a) = array_values(imageColorsForIndex($im, $idx));
- $r /=255; $r -=5; $r *=$adjust; $r +=5; $r *=255;
- if($r>255) $r=255;
- $g /=255; $g -=5; $g *=$adjust; $g +=5; $g *=255;
- if($g>255) $g=255;
- $b /=255; $b -=5; $b *=$adjust; $b +=5; $b *=255;
- if($b>255) $b=255;
- $col = imageColorAllocate($newimg, $r,$g,$b);
- imageSetPixel($newimg,$x,$y,$col);
- }
- }
- return $newimg;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement