wpfunnels
/
vendor
/
intervention
/
image
/
src
/
Intervention
/
Image
/
Commands
/
PolygonCommand.php
PolygonCommand.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.3, at vendor/intervention/image/src/Intervention/Image/Commands/PolygonCommand.php
| 1 | <?php |
| 2 | |
| 3 | namespace Intervention\Image\Commands; |
| 4 | |
| 5 | use Closure; |
| 6 | use Intervention\Image\Exception\InvalidArgumentException; |
| 7 | |
| 8 | class PolygonCommand extends AbstractCommand |
| 9 | { |
| 10 | /** |
| 11 | * Draw a polygon on given image |
| 12 | * |
| 13 | * @param \Intervention\Image\image $image |
| 14 | * @return boolean |
| 15 | */ |
| 16 | public function execute($image) |
| 17 | { |
| 18 | $points = $this->argument(0)->type('array')->required()->value(); |
| 19 | $callback = $this->argument(1)->type('closure')->value(); |
| 20 | |
| 21 | $vertices_count = count($points); |
| 22 | |
| 23 | // check if number if coordinates is even |
| 24 | if ($vertices_count % 2 !== 0) { |
| 25 | throw new InvalidArgumentException( |
| 26 | "The number of given polygon vertices must be even." |
| 27 | ); |
| 28 | } |
| 29 | |
| 30 | if ($vertices_count < 6) { |
| 31 | throw new InvalidArgumentException( |
| 32 | "You must have at least 3 points in your array." |
| 33 | ); |
| 34 | } |
| 35 | |
| 36 | $polygon_classname = sprintf('\Intervention\Image\%s\Shapes\PolygonShape', |
| 37 | $image->getDriver()->getDriverName()); |
| 38 | |
| 39 | $polygon = new $polygon_classname($points); |
| 40 | |
| 41 | if ($callback instanceof Closure) { |
| 42 | $callback($polygon); |
| 43 | } |
| 44 | |
| 45 | $polygon->applyToImage($image); |
| 46 | |
| 47 | return true; |
| 48 | } |
| 49 | } |
| 50 |