<?php
namespace Intervention\Image\Commands;
use Closure;
use Intervention\Image\Exception\InvalidArgumentException;
class PolygonCommand extends AbstractCommand
{
/**
* Draw a polygon on given image
*
* @param \Intervention\Image\image $image
* @return boolean
*/
public function execute($image)
{
$points = $this->argument(0)->type('array')->required()->value();
$callback = $this->argument(1)->type('closure')->value();
$vertices_count = count($points);
// check if number if coordinates is even
if ($vertices_count % 2 !== 0) {
throw new InvalidArgumentException(
"The number of given polygon vertices must be even."
);
}
if ($vertices_count < 6) {
throw new InvalidArgumentException(
"You must have at least 3 points in your array."
);
}
$polygon_classname = sprintf('\Intervention\Image\%s\Shapes\PolygonShape',
$image->getDriver()->getDriverName());
$polygon = new $polygon_classname($points);
if ($callback instanceof Closure) {
$callback($polygon);
}
$polygon->applyToImage($image);
return true;
}
}
How To Payment
Making a payment on our website is quick and secure. Start by logging in or creating an account. Select your preferred payment method, input the required details, and review the information. Once you confirm everything is correct, click on the "Submit Payment" button. You’ll receive instant confirmation and can track your payment status through your account dashboard. It’s an easy and secure process.