Exemplo n.º 1
0
 /**
  * Draw a circle centered on given image
  *
  * @param  \Intervention\Image\image $image
  * @return boolean
  */
 public function execute($image)
 {
     $radius = $this->argument(0)->type('numeric')->required()->value();
     $x = $this->argument(1)->type('numeric')->required()->value();
     $y = $this->argument(2)->type('numeric')->required()->value();
     $callback = $this->argument(3)->type('closure')->value();
     $circle_classname = sprintf('\\Intervention\\Image\\%s\\Shapes\\CircleShape', $image->getDriver()->getDriverName());
     $circle = new $circle_classname($radius);
     if ($callback instanceof Closure) {
         $callback($circle);
     }
     $circle->applyToImage($image, $x, $y);
     return true;
 }
Exemplo n.º 2
0
 /**
  * Draw a polygon on given image
  *
  * @param  \Intervention\Image\image $image
  * @return boolean
  */
 public function execute($image)
 {
     $points = $this->argument(0)->type('array')->required()->value();
     $callback = $this->argument(1)->type('closure')->value();
     $vertices_count = count($points);
     // check if number if coordinates is even
     if ($vertices_count % 2 !== 0) {
         throw new \Intervention\Image\Exception\InvalidArgumentException("The number of given polygon vertices must be even.");
     }
     if ($vertices_count < 6) {
         throw new \Intervention\Image\Exception\InvalidArgumentException("You must have at least 3 points in your array.");
     }
     $polygon_classname = sprintf('\\Intervention\\Image\\%s\\Shapes\\PolygonShape', $image->getDriver()->getDriverName());
     $polygon = new $polygon_classname($points);
     if ($callback instanceof Closure) {
         $callback($polygon);
     }
     $polygon->applyToImage($image);
     return true;
 }