Exemple #1
0
 private function normalize(ImageInterface $image)
 {
     $step = (int) round(255 / $this->buckets);
     $red = $green = $blue = $alpha = array();
     for ($i = 1; $i <= $this->buckets; $i++) {
         $range = new Range(($i - 1) * $step, $i * $step);
         $red[] = new Bucket($range);
         $green[] = new Bucket($range);
         $blue[] = new Bucket($range);
         $alpha[] = new Bucket($range);
     }
     foreach ($image->histogram() as $color) {
         foreach ($red as $bucket) {
             $bucket->add($color->getRed());
         }
         foreach ($green as $bucket) {
             $bucket->add($color->getGreen());
         }
         foreach ($blue as $bucket) {
             $bucket->add($color->getBlue());
         }
         foreach ($alpha as $bucket) {
             $bucket->add($color->getAlpha());
         }
     }
     $total = $image->getSize()->square();
     $callback = function (Bucket $bucket) use($total) {
         return count($bucket) / $total;
     };
     return array(array_map($callback, $red), array_map($callback, $green), array_map($callback, $blue), array_map($callback, $alpha));
 }
Exemple #2
0
 /**
  * (non-PHPdoc)
  * @see Imagine\ImageInterface::applyMask()
  */
 public function applyMask(ImageInterface $mask)
 {
     if (!$mask instanceof self) {
         throw new InvalidArgumentException('Can only apply instances of Imagine\\Gmagick\\Image as masks');
     }
     $size = $this->getSize();
     $maskSize = $mask->getSize();
     if ($size != $maskSize) {
         throw new InvalidArgumentException(sprintf('The given mask doesn\'t match current image\'s sise, current ' . 'mask\'s dimensions are %s, while image\'s dimensions are %s', $maskSize, $size));
     }
     try {
         $mask = $mask->copy();
         $this->gmagick->compositeimage($mask->gmagick, \Gmagick::COMPOSITE_DEFAULT, 0, 0);
     } catch (\Exception $e) {
         throw new RuntimeException('Apply mask operation failed', $e->getCode(), $e);
     }
     return $this;
 }
Exemple #3
0
 /**
  * (non-PHPdoc)
  * @see Imagine\Filter\FilterInterface::apply()
  */
 public function apply(ImageInterface $image)
 {
     return $image->copy();
 }
Exemple #4
0
 /**
  * (non-PHPdoc)
  * @see Imagine\Filter\FilterInterface::apply()
  */
 public function apply(ImageInterface $image)
 {
     return $image->resize($this->size);
 }
Exemple #5
0
 /**
  * (non-PHPdoc)
  * @see Imagine\Filter\FilterInterface::apply()
  */
 public function apply(ImageInterface $image)
 {
     return $image->show($this->format, $this->options);
 }
Exemple #6
0
 /**
  * (non-PHPdoc)
  * @see Imagine\Filter\FilterInterface::apply()
  */
 public function apply(ImageInterface $image)
 {
     return $image->rotate($this->angle, $this->background);
 }
Exemple #7
0
 /**
  * (non-PHPdoc)
  * @see Imagine\Filter\FilterInterface::apply()
  */
 public function apply(ImageInterface $image)
 {
     return $image->flipHorizontally();
 }
Exemple #8
0
 /**
  * (non-PHPdoc)
  * @see Imagine\Filter\FilterInterface::apply()
  */
 public function apply(ImageInterface $image)
 {
     return $image->crop($this->start, $this->size);
 }
Exemple #9
0
 /**
  * (non-PHPdoc)
  * @see Imagine\Filter\FilterInterface::apply()
  */
 public function apply(ImageInterface $image)
 {
     return $image->save($this->path, $this->options);
 }
Exemple #10
0
 /**
  * (non-PHPdoc)
  * @see Imagine\ImageInterface::applyMask()
  */
 public function applyMask(ImageInterface $mask)
 {
     if (!$mask instanceof self) {
         throw new InvalidArgumentException('Cannot mask non-gd images');
     }
     $size = $this->getSize();
     $maskSize = $mask->getSize();
     if ($size != $maskSize) {
         throw new InvalidArgumentException(sprintf('The given mask doesn\'t match current image\'s sise, Current ' . 'mask\'s dimensions are %s, while image\'s dimensions are %s', $maskSize, $size));
     }
     for ($x = 0; $x < $size->getWidth(); $x++) {
         for ($y = 0; $y < $size->getHeight(); $y++) {
             $color = imagecolorat($this->resource, $x, $y);
             $info = imagecolorsforindex($this->resource, $color);
             $maskColor = $color = imagecolorat($mask->resource, $x, $y);
             $maskInfo = imagecolorsforindex($mask->resource, $maskColor);
             if (false === imagesetpixel($this->resource, $x, $y, imagecolorallocatealpha($this->resource, $info['red'], $info['green'], $info['blue'], round((127 - $info['alpha']) * $maskInfo['red'] / 255)))) {
                 throw new RuntimeException('Apply mask operation failed');
             }
         }
     }
     return $this;
 }
Exemple #11
0
 /**
  * (non-PHPdoc)
  * @see Imagine\Filter\FilterInterface::apply()
  */
 public function apply(ImageInterface $image)
 {
     return $image->paste($this->image, $this->start);
 }
Exemple #12
0
 /**
  * (non-PHPdoc)
  * @see Imagine\Filter\FilterInterface::apply()
  */
 public function apply(ImageInterface $image)
 {
     return $image->thumbnail($this->size, $this->mode);
 }
Exemple #13
0
 /**
  * (non-PHPdoc)
  * @see Imagine\Filter\FilterInterface::apply()
  */
 public function apply(ImageInterface $image)
 {
     return $image->flipVertically();
 }