/** * 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; }
/** * {@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; }
/** * {@inheritdoc} */ public function apply(ImageInterface $image) { return $image->resize(call_user_func(array($image->getSize(), $this->method), $this->parameter)); }
/** * {@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; }
/** * {@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; }
/** * {@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; }