LineCommand.php 998 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace Intervention\Image\Commands;
  3. use \Closure;
  4. class LineCommand extends \Intervention\Image\Commands\AbstractCommand
  5. {
  6. /**
  7. * Draws line 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. $line_classname = sprintf('\Intervention\Image\%s\Shapes\LineShape',
  20. $image->getDriver()->getDriverName());
  21. $line = new $line_classname($x2, $y2);
  22. if ($callback instanceof Closure) {
  23. $callback($line);
  24. }
  25. $line->applyToImage($image, $x1, $y1);
  26. return true;
  27. }
  28. }