Cheetah
All Classes Namespaces Files Functions Variables Pages
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  return $this->modify($image, 0, 0, $position->x, $position->y, $cropped->width, $cropped->height, $cropped->width, $cropped->height);
39  }
40 }
Intervention\Image\Gd\Commands\ResizeCommand\modify
modify($image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
Definition: ResizeCommand.php:42
Intervention\Image\Gd\Commands
Definition: BackupCommand.php:3
Intervention\Image\Point
Definition: Point.php:6
php
Intervention\Image\Gd\Commands\CropCommand
Definition: CropCommand.php:9
Intervention\Image\Gd\Commands\CropCommand\execute
execute($image)
Definition: CropCommand.php:16
Intervention\Image\Commands\AbstractCommand\argument
argument($key)
Definition: AbstractCommand.php:45
Intervention\Image\Gd\Commands\ResizeCommand
Definition: ResizeCommand.php:6
Intervention\Image\Size
Definition: Size.php:8