TextCommand.php 861 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace Intervention\Image\Commands;
  3. use \Closure;
  4. class TextCommand extends \Intervention\Image\Commands\AbstractCommand
  5. {
  6. /**
  7. * Write text on given image
  8. * @param \Intervention\Image\Image $image
  9. * @return boolean
  10. */
  11. public function execute($image)
  12. {
  13. $text = $this->argument(0)->required()->value();
  14. $x = $this->argument(1)->type('numeric')->value(0);
  15. $y = $this->argument(2)->type('numeric')->value(0);
  16. $callback = $this->argument(3)->type('closure')->value();
  17. $fontclassname = sprintf('\Intervention\Image\%s\Font',
  18. $image->getDriver()->getDriverName());
  19. $font = new $fontclassname($text);
  20. if ($callback instanceof Closure) {
  21. $callback($font);
  22. }
  23. $font->applyToImage($image, $x, $y);
  24. return true;
  25. }
  26. }