Exemplo n.º 1
0
 /**
  * Applies scheduled transformation to ImageInterface instance
  * Returns processed ImageInterface instance
  *
  * @param ImageInterface $image
  *
  * @return ImageInterface
  */
 public function apply(ImageInterface $image)
 {
     $w = $image->getSize()->getWidth();
     $h = $image->getSize()->getHeight();
     for ($x = 0; $x < $w; $x++) {
         for ($y = 0; $y < $h; $y++) {
             call_user_func($this->callback, $image, new Point($x, $y));
         }
     }
     return $image;
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     $size = $image->getSize();
     $width = $size->getWidth();
     $height = $size->getHeight();
     $draw = $image->draw();
     // Draw top and bottom lines
     $draw->line(new Point(0, 0), new Point($width - 1, 0), $this->color, $this->height)->line(new Point($width - 1, $height - 1), new Point(0, $height - 1), $this->color, $this->height);
     // Draw sides
     $draw->line(new Point(0, 0), new Point(0, $height - 1), $this->color, $this->width)->line(new Point($width - 1, 0), new Point($width - 1, $height - 1), $this->color, $this->width);
     return $image;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     $image->usePalette($this->palette)->strip();
     if (is_callable($this->path)) {
         $path = call_user_func($this->path, $image);
     } elseif (null !== $this->path) {
         $path = $this->path;
     } else {
         return $image;
     }
     return $image->save($path, $this->options);
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     return $image->flipHorizontally();
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     return $image->show($this->format, $this->options);
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     return $image->thumbnail($this->size, $this->mode, $this->filter);
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     return $image->resize(call_user_func(array($image->getSize(), $this->method), $this->parameter));
 }
Exemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     return $image->rotate($this->angle, $this->background);
 }
Exemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     return $image->paste($this->image, $this->start);
 }
Exemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     return $image->flipVertically();
 }
Exemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     return $image->save($this->path, $this->options);
 }
Exemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     return $image->fill($this->fill);
 }
Exemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     return $image->copy();
 }
Exemplo n.º 14
0
 /**
  * {@inheritdoc}
  *
  * @return ImageInterface
  */
 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 size, 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 (\GmagickException $e) {
         throw new RuntimeException('Apply mask operation failed', $e->getCode(), $e);
     }
     return $this;
 }
Exemplo n.º 15
0
 /**
  * {@inheritdoc}
  *
  * @return ImageInterface
  */
 public function applyMask(ImageInterface $mask)
 {
     if (!$mask instanceof self) {
         throw new InvalidArgumentException('Can only apply instances of Imagine\\Imagick\\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 size, Current mask\'s dimensions are %s, while image\'s dimensions are %s', $maskSize, $size));
     }
     $mask = $mask->mask();
     $mask->imagick->negateImage(true);
     try {
         // remove transparent areas of the original from the mask
         $mask->imagick->compositeImage($this->imagick, \Imagick::COMPOSITE_DSTIN, 0, 0);
         $this->imagick->compositeImage($mask->imagick, \Imagick::COMPOSITE_COPYOPACITY, 0, 0);
         $mask->imagick->clear();
         $mask->imagick->destroy();
     } catch (\ImagickException $e) {
         throw new RuntimeException('Apply mask operation failed', $e->getCode(), $e);
     }
     return $this;
 }
Exemplo n.º 16
0
 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     return $image->crop($this->start, $this->size);
 }
Exemplo n.º 17
0
 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     return $image->strip();
 }
Exemplo n.º 18
0
 /**
  * {@inheritdoc}
  *
  * @return ImageInterface
  */
 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 size, Current mask\'s dimensions are %s, while image\'s dimensions are %s', $maskSize, $size));
     }
     for ($x = 0, $width = $size->getWidth(); $x < $width; $x++) {
         for ($y = 0, $height = $size->getHeight(); $y < $height; $y++) {
             $position = new Point($x, $y);
             $color = $this->getColorAt($position);
             $maskColor = $mask->getColorAt($position);
             $round = (int) round(max($color->getAlpha(), (100 - $color->getAlpha()) * $maskColor->getRed() / 255));
             if (false === imagesetpixel($this->resource, $x, $y, $this->getColor($color->dissolve($round - $color->getAlpha())))) {
                 throw new RuntimeException('Apply mask operation failed');
             }
         }
     }
     return $this;
 }
Exemplo n.º 19
0
 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     return $image->applyMask($this->mask);
 }
Exemplo n.º 20
0
 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     return $image->resize($this->size, $this->filter);
 }