/**
  * {@inheritdoc}
  */
 public function apply(CanvasInterface $canvas, AbstractStyledDrawable $drawable)
 {
     if (false == @imagesettile($canvas->getHandler(), $this->pattern->getHandler())) {
         throw new DrawableException('Could Not Apply The Fill Pattern Style');
     }
     return new TiledColor();
 }
 /**
  * {@inheritdoc}
  */
 public function draw(CanvasInterface $canvas, Border $border, StyleInterface $style = null)
 {
     $rect = new Rectangle($canvas->getDimension());
     $color = $style ? $style->apply($canvas, $border) : $border->getColor();
     $rect->setColor($color)->setLineThickness($border->getSize())->draw($canvas);
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 protected function doApply(CanvasInterface $canvas)
 {
     $width = $canvas->getWidth();
     $height = $canvas->getHeight();
     $copy = new \Jaguar\Canvas($canvas->getDimension());
     $srcBox = null;
     $destBox = null;
     switch ($this->getDirection()) {
         case self::FLIP_VERTICAL:
             $srcBox = new Box(new Dimension($width, -$height), new Coordinate(0, $height - 1));
             $destBox = new Box(new Dimension($width, $height), new Coordinate(0, 0));
             break;
         case self::FLIP_HORIZONTAL:
             $srcBox = new Box(new Dimension(-$width, $height), new Coordinate($width - 1, 0));
             $destBox = new Box(new Dimension($width, $height), new Coordinate(0, 0));
             break;
         case self::FLIP_BOTH:
             $srcBox = new Box(new Dimension(-$width, -$height), new Coordinate($width - 1, $height - 1));
             $destBox = new Box(new Dimension($width, $height), new Coordinate(0, 0));
             break;
     }
     $copy->paste($canvas, $srcBox, $destBox);
     $canvas->destroy();
     $canvas->setHandler($copy->getHandler());
 }
 /**
  * {@inheritdoc}
  */
 protected function doApply(CanvasInterface $canvas)
 {
     $dimension = $canvas->getDimension();
     $newDimension = new Dimension(2, $dimension->getHeight());
     for ($i = 0; $i < $dimension->getWidth(); $i += 2) {
         $canvas->paste($canvas, new Box($newDimension, new Coordinate($i, 0)), new Box($newDimension, new Coordinate($i - 2, sin($i / 10) * $this->getLevel())));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function apply(CanvasInterface $canvas)
 {
     if (!$canvas->isHandlerSet()) {
         throw new CanvasEmptyException();
     }
     $this->doApply($canvas);
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public final function draw(CanvasInterface $canvas, StyleInterface $style = null)
 {
     if (!$canvas->isHandlerSet()) {
         throw new CanvasEmptyException(sprintf('Can Not Draw Drawable (%s) - Canvas Is Empty', (string) $this));
     }
     @imagesetthickness($canvas->getHandler(), $this->getLineThickness());
     $this->doDraw($canvas, $style);
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function draw(CanvasInterface $canvas, Border $border, StyleInterface $style = null)
 {
     $size = $border->getSize();
     $new = new Canvas($canvas->getDimension());
     $new->paste($canvas, null, new Box($canvas->getDimension()->translate(-$size, -$size + 1), new Coordinate($size / 2, $size / 2)));
     $in = new BorderIn();
     $in->draw($new, $border, $style);
     $canvas->destroy();
     $canvas->setHandler($new->getHandler());
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 protected function doApply(CanvasInterface $canvas)
 {
     $copy = $canvas->getCopy();
     // convert copy to black and white
     $baw = new BlackAndWhite();
     $baw->apply($copy);
     // overlay the canvas with the black and white copy
     $overlay = new Overlay($copy, $this->getLevel());
     $overlay->apply($canvas);
     $copy->destroy();
 }
 /**
  * {@inheritdoc}
  */
 protected function doGenerate(CanvasInterface $canvas)
 {
     $width = $canvas->getWidth();
     $height = $canvas->getHeight();
     $n = sqrt(pow($width, 2) + pow($height, 2));
     $arc = new Arc(null, new Coordinate($width / 2, $height / 2));
     $arc->fill(true);
     for ($i = 0; $i < $n; $i += $this->getStep() + 1) {
         $arc->getDimension()->resize($n - $i, $n - $i);
         $arc->setColor($this->getColor($i / $n))->draw($canvas);
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function doGenerate(CanvasInterface $canvas)
 {
     $width = $canvas->getWidth();
     $height = $canvas->getHeight();
     $n = max($width, $height) / 2;
     $rect = new Rectangle();
     $rect->fill(true);
     for ($i = 0; $i < $n; $i += $this->getStep() + 1) {
         $rect->getStart()->move($i * $width / $height, $i * $height / $width);
         $rect->getDimension()->resize($width - $i * $width / $height - $rect->getStart()->getX(), $height - $i * $height / $width - $rect->getStart()->getY());
         $rect->setColor($this->getColor($i / $n))->draw($canvas);
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function doGenerate(CanvasInterface $canvas)
 {
     $width = $canvas->getWidth();
     $height = $canvas->getHeight();
     $ry = $height > $width ? 1 : $width / $height;
     $rx = $width > $height ? 1 : $height / $width;
     $n = min($width, $height);
     $poly = new Polygon();
     $poly->fill(true);
     for ($i = 0; $i < $n; $i += $this->getStep() + 1) {
         $coordinates = array(new Coordinate($width / 2, $i * $rx - 0.5 * $height), new Coordinate($i * $ry - 0.5 * $width, $height / 2), new Coordinate($width / 2, 1.5 * $height - $i * $rx), new Coordinate(1.5 * $width - $i * $ry, $height / 2));
         $poly->setCoordinate(new \ArrayObject($coordinates))->setColor($this->getColor($i / $n))->draw($canvas);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function draw(CanvasInterface $canvas, Text $text)
 {
     $x = $text->getCoordinate()->getX();
     $y = $text->getCoordinate()->getY();
     $width = $this->getWidth();
     $outlineColor = $this->getColor()->getValue();
     $result = true;
     for ($xc = $x - abs($width); $xc <= $x + abs($width); $xc++) {
         for ($yc = $y - abs($width); $yc <= $y + abs($width); $yc++) {
             $result = @imagefttext($canvas->getHandler(), $text->getFontSize(), $text->getAngle(), $xc, $yc + $text->getFontSize(), $outlineColor, $text->getFont(), $text->getString(), array('linespacing' => $text->getLineSpacing()));
         }
     }
     return (bool) ($result && @imagefttext($canvas->getHandler(), $text->getFontSize(), $text->getAngle(), $text->getCoordinate()->getX(), $text->getCoordinate()->getY() + $text->getFontSize(), $text->getColor()->getValue(), $text->getFont(), $text->getString(), array('linespacing' => $text->getLineSpacing())));
 }
 /**
  * {@inheritdoc}
  */
 protected function doApply(CanvasInterface $canvas)
 {
     $colors = array(new RGBColor(0, 0, 150, 100), new RGBColor(255, 0, 0, 100), new RGBColor(0, 0, 0, 100), new RGBColor(150, 0, 0, 100), new RGBColor(255, 204, 0, 100), new RGBColor(100, 100, 100, 100));
     $width = round($canvas->getWidth() / 6);
     $dimension = new Dimension($width, $canvas->getHeight());
     $rect = new Rectangle($dimension);
     $rect->fill(true);
     for ($i = 0; $i < 6; $i++) {
         $rect->getStart()->move($width * $i, 0);
         $rect->setColor($colors[$i])->draw($canvas);
     }
     $actions = array(new Smooth(20), new Color\Contrast(35));
     foreach ($actions as $action) {
         $action->apply($canvas);
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function doApply(CanvasInterface $canvas)
 {
     $width = $canvas->getWidth();
     $height = $canvas->getHeight();
     $mirrorPoint = null;
     $srcBox = null;
     $destBox = null;
     switch ($this->getdirection()) {
         case self::MIRROR_VERTICAL:
             $mirrorPoint = $width / 2;
             $srcBox = new Box(new Dimension(-$mirrorPoint, $height), new Coordinate($mirrorPoint - 1, 0));
             $destBox = new Box(new Dimension($mirrorPoint, $height), new Coordinate($mirrorPoint, 0));
             break;
         case self::MIRROR_HORIZONTAL:
             $mirrorPoint = $height / 2;
             $srcBox = new Box(new Dimension($width, -$mirrorPoint), new Coordinate(0, $mirrorPoint - 1));
             $destBox = new Box(new Dimension($width, $mirrorPoint), new Coordinate(0, $mirrorPoint));
             break;
     }
     $canvas->paste($canvas, $srcBox, $destBox);
 }
 /**
  * {@inheritdoc}
  */
 protected function doApply(CanvasInterface $canvas)
 {
     $width = $canvas->getWidth();
     $height = $canvas->getHeight();
     $line = new Line();
     $line->setColor($this->getColor());
     for ($x = 1; $x <= $width; $x += $this->getSize()) {
         $line->getStart()->move($x, 0);
         $line->getEnd()->move($x, $height);
         $line->draw($canvas);
     }
     for ($y = 1; $y <= $height; $y += $this->getSize()) {
         $line->getStart()->move(0, $y);
         $line->getEnd()->move($width, $y);
         $line->draw($canvas);
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function doGenerate(CanvasInterface $canvas)
 {
     $n = $w = null;
     if (self::GRADIENT_VERTICAL == $this->getType()) {
         $n = $canvas->getHeight();
         $w = $canvas->getWidth();
     } else {
         $w = $canvas->getHeight();
         $n = $canvas->getWidth();
     }
     $rect = new Rectangle();
     $rect->fill(true);
     for ($i = 0; $i < $n; $i += $this->getStep() + 1) {
         if (self::GRADIENT_VERTICAL == $this->getType()) {
             $rect->getStart()->move(0, $i);
             $rect->getDimension()->resize($w, $i + $this->getStep());
         } else {
             $rect->getStart()->move($i, 0);
             $rect->getDimension()->resize($i + $this->getStep(), $w);
         }
         $rect->setColor($this->getColor($i / $n))->draw($canvas);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function apply(CanvasInterface $canvas, AbstractStyledDrawable $drawable)
 {
     $fv = $drawable->getColor()->getValue();
     $sv = $this->getSecondColor()->getValue();
     $style = array_merge(array_fill(0, $this->getFirstColorShowTime(), $fv), array_fill(0, $this->getSecondColorShowTime(), $sv));
     if (false == @imagesetstyle($canvas->getHandler(), $style)) {
         throw new DrawableException('Could Not Apply The DashedLine Style');
     }
     return new StyledColor();
 }
 /**
  * {@inheritdoc}
  */
 protected function doApply(CanvasInterface $canvas)
 {
     $box = is_null($this->getBox()) ? new Box($canvas->getDimension()) : $this->getBox();
     $compine = new \Jaguar\Canvas($canvas->getDimension());
     $compine->paste($canvas);
     $compine->paste($this->getOverlay(), null, $box);
     imagelayereffect($canvas->getHandler(), IMG_EFFECT_OVERLAY);
     imagecopymerge($canvas->getHandler(), $compine->getHandler(), 0, 0, 0, 0, $canvas->getWidth(), $canvas->getHeight(), $this->getAmount());
     $canvas->alphaBlending(true);
     $compine->destroy();
 }
 /**
  * {@inheritdoc}
  */
 protected function doApply(CanvasInterface $canvas)
 {
     imagefilter($canvas->getHandler(), IMG_FILTER_CONTRAST, -$this->getLevel());
 }
 /**
  * {@inheritdoc}
  */
 protected function doApply(CanvasInterface $canvas)
 {
     imagefilter($canvas->getHandler(), IMG_FILTER_MEAN_REMOVAL);
 }
 /**
  * {@inheritdoc}
  */
 protected function doApply(CanvasInterface $canvas)
 {
     imagefilter($canvas->getHandler(), IMG_FILTER_BRIGHTNESS, $this->getLevel());
 }
 /**
  * {@inheritdoc}
  */
 protected function doApply(CanvasInterface $canvas)
 {
     $copy = $canvas->getCopy();
     $this->isInvert() ? $this->getAction()->apply($canvas) : $this->getAction()->apply($copy);
     // do the magic
     $canvas->paste($copy, $this->getBox(), $this->getBox());
     // destroy the copy
     $copy->destroy();
 }
 /**
  * {@inheritdoc}
  */
 protected function doApply(CanvasInterface $canvas)
 {
     imagefilter($canvas->getHandler(), IMG_FILTER_PIXELATE, $this->getBlockSize(), false);
 }
 /**
  * {@inheritdoc}
  */
 public function apply(CanvasInterface $canvas, AbstractStyledDrawable $drawable)
 {
     $interval = array_merge(array_fill(0, $this->getShowTime(), 1), $this->getHideTime() == 0 ? array() : array_fill(0, $this->getHideTime(), 0));
     if (false == @imagesetstyle($canvas->getHandler(), $interval) || false == @imagesetbrush($canvas->getHandler(), $this->brush->getHandler())) {
         throw new DrawableException('Could Not Set The Brush And Interval');
     }
     return new StyledBrushedColor();
 }
 /**
  * {@inheritdoc}
  */
 protected function doApply(CanvasInterface $canvas)
 {
     imagefilter($canvas->getHandler(), IMG_FILTER_NEGATE);
 }
 /**
  * {@inheritdoc}
  */
 protected function doApply(CanvasInterface $canvas)
 {
     imagefilter($canvas->getHandler(), IMG_FILTER_COLORIZE, $this->getColor()->getRed(), $this->getColor()->getGreen(), $this->getColor()->getBlue(), $this->getColor()->getAlpha());
 }
 /**
  * {@inheritdoc}
  */
 protected function doApply(CanvasInterface $canvas)
 {
     imagefilter($canvas->getHandler(), IMG_FILTER_SELECTIVE_BLUR);
 }
 /**
  * {@inheritdoc}
  */
 protected function doApply(CanvasInterface $canvas)
 {
     imagegammacorrect($canvas->getHandler(), 1.0, $this->getLevel());
 }
 /**
  * {@inheritdoc}
  */
 protected function doApply(CanvasInterface $canvas)
 {
     $dimension = $this->getWatermark()->getDimension();
     $canvas->paste($this->getWatermark(), new Box($dimension), new Box($dimension, $this->getCoordinate()));
 }
 /**
  * {@inheritdoc}
  */
 public function draw(CanvasInterface $canvas, Text $text)
 {
     return (bool) @imagefttext($canvas->getHandler(), $text->getFontSize(), $text->getAngle(), $text->getCoordinate()->getX(), $text->getCoordinate()->getY() + $text->getFontSize(), $text->getColor()->getValue(), $text->getFont(), $text->getString(), array('linespacing' => $text->getLineSpacing()));
 }