File indexing completed on 2025-01-26 05:29:13

0001 <?php
0002 
0003 namespace Intervention\Image\Commands;
0004 
0005 use Closure;
0006 
0007 class LineCommand extends \Intervention\Image\Commands\AbstractCommand
0008 {
0009     /**
0010      * Draws line on given image
0011      *
0012      * @param  \Intervention\Image\Image $image
0013      * @return boolean
0014      */
0015     public function execute($image)
0016     {
0017         $x1 = $this->argument(0)->type('numeric')->required()->value();
0018         $y1 = $this->argument(1)->type('numeric')->required()->value();
0019         $x2 = $this->argument(2)->type('numeric')->required()->value();
0020         $y2 = $this->argument(3)->type('numeric')->required()->value();
0021         $callback = $this->argument(4)->type('closure')->value();
0022 
0023         $line_classname = sprintf('\Intervention\Image\%s\Shapes\LineShape',
0024             $image->getDriver()->getDriverName());
0025 
0026         $line = new $line_classname($x2, $y2);
0027 
0028         if ($callback instanceof Closure) {
0029             $callback($line);
0030         }
0031 
0032         $line->applyToImage($image, $x1, $y1);
0033 
0034         return true;
0035     }
0036 }