RectangleCommand.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace Intervention\Image\Commands;
  3. use Closure;
  4. class RectangleCommand extends \Intervention\Image\Commands\AbstractCommand
  5. {
  6. /**
  7. * Draws rectangle on given image
  8. *
  9. * @param \Intervention\Image\Image $image
  10. * @return boolean
  11. */
  12. public function execute($image)
  13. {
  14. $x1 = $this->argument(0)->type('numeric')->required()->value();
  15. $y1 = $this->argument(1)->type('numeric')->required()->value();
  16. $x2 = $this->argument(2)->type('numeric')->required()->value();
  17. $y2 = $this->argument(3)->type('numeric')->required()->value();
  18. $callback = $this->argument(4)->type('closure')->value();
  19. $rectangle_classname = sprintf('\Intervention\Image\%s\Shapes\RectangleShape',
  20. $image->getDriver()->getDriverName());
  21. $rectangle = new $rectangle_classname($x1, $y1, $x2, $y2);
  22. if ($callback instanceof Closure) {
  23. $callback($rectangle);
  24. }
  25. $rectangle->applyToImage($image, $x1, $y1);
  26. return true;
  27. }
  28. }