Cheetah
CropCommand.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use \Intervention\Image\Point;
6 use \Intervention\Image\Size;
7 
9 {
16  public function execute($image)
17  {
18  $width = $this->argument(0)->type('digit')->required()->value();
19  $height = $this->argument(1)->type('digit')->required()->value();
20  $x = $this->argument(2)->type('digit')->value();
21  $y = $this->argument(3)->type('digit')->value();
22 
23  if (is_null($width) || is_null($height)) {
24  throw new \Intervention\Image\Exception\InvalidArgumentException(
25  "Width and height of cutout needs to be defined."
26  );
27  }
28 
29  $cropped = new Size($width, $height);
30  $position = new Point($x, $y);
31 
32  // align boxes
33  if (is_null($x) && is_null($y)) {
34  $position = $image->getSize()->align('center')->relativePosition($cropped->align('center'));
35  }
36 
37  // crop image core
38  $image->getCore()->cropImage($cropped->width, $cropped->height, $position->x, $position->y);
39  $image->getCore()->setImagePage(0,0,0,0);
40 
41  return true;
42  }
43 }
Intervention\Image\Imagick\Commands\CropCommand
Definition: CropCommand.php:9
Intervention\Image\Point
Definition: Point.php:6
Intervention\Image\Imagick\Commands\CropCommand\execute
execute($image)
Definition: CropCommand.php:16
php
Intervention\Image\Imagick\Commands
Definition: BackupCommand.php:3
Intervention\Image\Commands\AbstractCommand\argument
argument($key)
Definition: AbstractCommand.php:45
Intervention\Image\Commands\AbstractCommand
Definition: AbstractCommand.php:6
Intervention\Image\Size
Definition: Size.php:8