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