Exemplo n.º 1
0
 /**
  * Takes samples from the given GD at 5 pixel increments
  * @param GDBackend $gd The source image
  * @param integer $horizontal Number of samples to take horizontally
  * @param integer $vertical Number of samples to take vertically
  * @return array List of colours for each sample, each given as an associative
  * array with red, blue, green, and alpha components
  */
 protected function sampleAreas(GDBackend $gd, $horizontal = 4, $vertical = 4)
 {
     $samples = array();
     for ($y = 0; $y < $vertical; $y++) {
         for ($x = 0; $x < $horizontal; $x++) {
             $colour = imagecolorat($gd->getImageResource(), $x * 5, $y * 5);
             $samples[] = ImageColorsforIndex($gd->getImageResource(), $colour);
         }
     }
     return $samples;
 }
 function greyscale($rv = 38, $gv = 36, $bv = 26)
 {
     $this->rv = $rv;
     $this->gv = $gv;
     $this->bv = $bv;
     $this->rt = $this->rv + $this->bv + $this->gv;
     $this->rr = $this->rv == 0 ? 0 : 1 / ($this->rt / $this->rv);
     $this->br = $this->bv == 0 ? 0 : 1 / ($this->rt / $this->bv);
     $this->gr = $this->gv == 0 ? 0 : 1 / ($this->rt / $this->gv);
     for ($this->dy = 0; $this->dy <= $this->r; $this->dy++) {
         for ($this->dx = 0; $this->dx <= $this->q; $this->dx++) {
             $this->pxrgb = @imagecolorat($this->t, $this->dx, $this->dy);
             $this->rgb = @ImageColorsforIndex($this->t, $this->pxrgb);
             $this->newcol = $this->rr * $this->rgb['red'] + $this->br * $this->rgb['blue'] + $this->gr * $this->rgb['green'];
             $this->setcol = @ImageColorAllocate($this->t, $this->newcol, $this->newcol, $this->newcol);
             @imagesetpixel($this->t, $this->dx, $this->dy, $this->setcol);
         }
     }
 }
 /**
  * Make the image greyscale
  * $rv = red value, defaults to 38
  * $gv = green value, defaults to 36
  * $bv = blue value, defaults to 26
  * Based (more or less entirely, with changes for readability) on code from
  * http://www.teckis.com/scriptix/thumbnails/teck.html
  */
 public function greyscale($rv = 38, $gv = 36, $bv = 26)
 {
     if (!$this->gd) {
         return null;
     }
     $width = $this->width;
     $height = $this->height;
     $newGD = imagecreatetruecolor($this->width, $this->height);
     // Preserves transparency between images
     imagealphablending($newGD, false);
     imagesavealpha($newGD, true);
     $rt = $rv + $bv + $gv;
     $rr = $rv == 0 ? 0 : 1 / ($rt / $rv);
     $br = $bv == 0 ? 0 : 1 / ($rt / $bv);
     $gr = $gv == 0 ? 0 : 1 / ($rt / $gv);
     for ($dy = 0; $dy < $height; $dy++) {
         for ($dx = 0; $dx < $width; $dx++) {
             $pxrgb = imagecolorat($this->gd, $dx, $dy);
             $heightgb = ImageColorsforIndex($this->gd, $pxrgb);
             $newcol = $rr * $heightgb['red'] + $br * $heightgb['blue'] + $gr * $heightgb['green'];
             $setcol = ImageColorAllocateAlpha($newGD, $newcol, $newcol, $newcol, $heightgb['alpha']);
             imagesetpixel($newGD, $dx, $dy, $setcol);
         }
     }
     $output = clone $this;
     $output->setImageResource($newGD);
     return $output;
 }
Exemplo n.º 4
0
 /**
  * Make the image greyscale.
  * Default color weights are based on standard BT.601 (those used in PAL, NTSC and many software packages, also see
  * https://en.wikipedia.org/wiki/Grayscale#Luma_coding_in_video_systems )
  *
  * $R = red weight, defaults to 299
  * $G = green weight, defaults to 587
  * $B = blue weight, defaults to 114
  * $brightness = brightness in percentage, defaults to 100
  */
 public function greyscale($R = 299, $G = 587, $B = 114, $brightness = 100)
 {
     $width = $this->width;
     $height = $this->height;
     $newGD = imagecreatetruecolor($this->width, $this->height);
     // Preserves transparency between images
     imagealphablending($newGD, false);
     imagesavealpha($newGD, true);
     $rt = $R + $G + $B;
     // if $rt is 0, bad parameters are provided, so result will be a black image
     $rr = $rt ? $R / $rt : 0;
     $gr = $rt ? $G / $rt : 0;
     $br = $rt ? $B / $rt : 0;
     // iterate over all pixels and make them grey
     for ($dy = 0; $dy < $height; $dy++) {
         for ($dx = 0; $dx < $width; $dx++) {
             $pxrgb = imagecolorat($this->gd, $dx, $dy);
             $heightgb = ImageColorsforIndex($this->gd, $pxrgb);
             $newcol = $rr * $heightgb['red'] + $br * $heightgb['blue'] + $gr * $heightgb['green'];
             $newcol = min(255, $newcol * $brightness / 100);
             $setcol = ImageColorAllocateAlpha($newGD, $newcol, $newcol, $newcol, $heightgb['alpha']);
             imagesetpixel($newGD, $dx, $dy, $setcol);
         }
     }
     $output = clone $this;
     $output->setImageResource($newGD);
     return $output;
 }
Exemplo n.º 5
0
 /**
  * Make the image greyscale
  * $rv = red value, defaults to 38
  * $gv = green value, defaults to 36
  * $bv = blue value, defaults to 26
  * Based (more or less entirely, with changes for readability) on code from http://www.teckis.com/scriptix/thumbnails/teck.html
  */
 function greyscale($rv = 38, $gv = 36, $bv = 26)
 {
     $width = $this->width;
     $height = $this->height;
     $newGD = imagecreatetruecolor($this->width, $this->height);
     $rt = $rv + $bv + $gv;
     $rr = $rv == 0 ? 0 : 1 / ($rt / $rv);
     $br = $bv == 0 ? 0 : 1 / ($rt / $bv);
     $gr = $gv == 0 ? 0 : 1 / ($rt / $gv);
     for ($dy = 0; $dy < $height; $dy++) {
         for ($dx = 0; $dx < $width; $dx++) {
             $pxrgb = imagecolorat($this->gd, $dx, $dy);
             $heightgb = ImageColorsforIndex($this->gd, $pxrgb);
             $newcol = $rr * $heightgb['red'] + $br * $heightgb['blue'] + $gr * $heightgb['green'];
             $setcol = ImageColorAllocate($newGD, $newcol, $newcol, $newcol);
             imagesetpixel($newGD, $dx, $dy, $setcol);
         }
     }
     $output = clone $this;
     $output->setGD($newGD);
     return $output;
 }
Exemplo n.º 6
0
 /**
  * Make the image greyscale
  * $rv = red value, defaults to 38
  * $gv = green value, defaults to 36
  * $bv = blue value, defaults to 26
  * Based (more or less entirely, with changes for readability) on code from http://www.teckis.com/scriptix/thumbnails/teck.html
  */
 function greyscale($rv = 38, $gv = 36, $bv = 26)
 {
     $width = $this->width;
     $height = $this->height;
     $newGD = imagecreatetruecolor($this->width, $this->height);
     $rt = $rv + $bv + $gv;
     $rr = $rv == 0 ? 0 : 1 / ($rt / $rv);
     $br = $bv == 0 ? 0 : 1 / ($rt / $bv);
     $gr = $gv == 0 ? 0 : 1 / ($rt / $gv);
     for ($dy = 0; $dy <= $height; $dy++) {
         for ($dx = 0; $dx <= $width; $dx++) {
             $pxrgb = imagecolorat($this->gd, $dx, $dy);
             $heightgb = ImageColorsforIndex($this->gd, $pxrgb);
             $newcol = $rr * $heightgb['red'] + $br * $heightgb['blue'] + $gr * $heightgb['green'];
             $setcol = ImageColorAllocate($newGD, $newcol, $newcol, $newcol);
             imagesetpixel($newGD, $dx, $dy, $setcol);
         }
     }
     // imagecopyresampled($newGD, $this->gd, 0,0, $srcX, $srcY, $width, $height, $srcWidth, $srcHeight);
     $output = new GD();
     $output->setGD($newGD);
     if ($this->quality) {
         $output->setQuality($this->quality);
     }
     return $output;
 }
 function greyscale($rv = 38, $gv = 36, $bv = 26)
 {
     //BOF - DokuMan - 2011-01-06
     // Not working properly for PNG & GIF images, so skipping
     if ($this->effects_disabled || $this->k == 3 || $this->k == 1) {
         return;
     }
     $this->bgc = $bg_colour;
     $this->br = $this->hex2rgb(substr($this->bgc, 0, 2));
     $this->bg = $this->hex2rgb(substr($this->bgc, 2, 2));
     $this->bb = $this->hex2rgb(substr($this->bgc, 4, 2));
     $this->dot = @ImageCreate(6, 6);
     $this->dot_base = @ImageColorAllocate($this->dot, $this->br, $this->bg, $this->bb);
     $this->zenitha = @ImageColorClosest($this->t, $this->br, $this->bg, $this->bb);
     for ($this->rad = 0; $this->rad < 6.3; $this->rad += 0.005) {
         $this->xpos = floor($this->q + sin($this->rad) * $this->q) / 2;
         $this->ypos = floor($this->r + cos($this->rad) * $this->r) / 2;
         $this->xto = 0;
         if ($this->xpos >= $this->q / 2) {
             $this->xto = $this->q;
         }
         @ImageCopyMerge($this->t, $this->dot, $this->xpos - 3, $this->ypos - 3, 0, 0, 6, 6, 30);
         @ImageCopyMerge($this->t, $this->dot, $this->xpos - 2, $this->ypos - 2, 0, 0, 4, 4, 30);
         @ImageCopyMerge($this->t, $this->dot, $this->xpos - 1, $this->ypos - 1, 0, 0, 2, 2, 30);
         //EOF - DokuMan - 2011-01-06
         $this->rv = $rv;
         $this->gv = $gv;
         $this->bv = $bv;
         $this->rt = $this->rv + $this->bv + $this->gv;
         $this->rr = $this->rv == 0 ? 0 : 1 / ($this->rt / $this->rv);
         $this->br = $this->bv == 0 ? 0 : 1 / ($this->rt / $this->bv);
         $this->gr = $this->gv == 0 ? 0 : 1 / ($this->rt / $this->gv);
         for ($this->dy = 0; $this->dy <= $this->r; $this->dy++) {
             for ($this->dx = 0; $this->dx <= $this->q; $this->dx++) {
                 $this->pxrgb = @imagecolorat($this->t, $this->dx, $this->dy);
                 $this->rgb = @ImageColorsforIndex($this->t, $this->pxrgb);
                 $this->newcol = $this->rr * $this->rgb['red'] + $this->br * $this->rgb['blue'] + $this->gr * $this->rgb['green'];
                 $this->setcol = @ImageColorAllocate($this->t, $this->newcol, $this->newcol, $this->newcol);
                 @imagesetpixel($this->t, $this->dx, $this->dy, $this->setcol);
             }
         }
     }
     //BOF - DokuMan - 2011-01-06
 }