Cheetah
PolygonCommand.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use \Closure;
6 
8 {
15  public function execute($image)
16  {
17  $points = $this->argument(0)->type('array')->required()->value();
18  $callback = $this->argument(1)->type('closure')->value();
19 
20  $vertices_count = count($points);
21 
22  // check if number if coordinates is even
23  if ($vertices_count % 2 !== 0) {
24  throw new \Intervention\Image\Exception\InvalidArgumentException(
25  "The number of given polygon vertices must be even."
26  );
27  }
28 
29  if ($vertices_count < 6) {
30  throw new \Intervention\Image\Exception\InvalidArgumentException(
31  "You must have at least 3 points in your array."
32  );
33  }
34 
35  $polygon_classname = sprintf('\Intervention\Image\%s\Shapes\PolygonShape',
36  $image->getDriver()->getDriverName());
37 
38  $polygon = new $polygon_classname($points);
39 
40  if ($callback instanceof Closure) {
41  $callback($polygon);
42  }
43 
44  $polygon->applyToImage($image);
45 
46  return true;
47  }
48 }
Intervention\Image\Commands\PolygonCommand
Definition: PolygonCommand.php:8
Intervention\Image\Commands
Definition: AbstractCommand.php:3
php
Intervention\Image\Commands\AbstractCommand\argument
argument($key)
Definition: AbstractCommand.php:45
Intervention\Image\Commands\AbstractCommand
Definition: AbstractCommand.php:6
Intervention\Image\Commands\PolygonCommand\execute
execute($image)
Definition: PolygonCommand.php:15