Cheetah
FitCommand.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use \Intervention\Image\Point;
6 use \Intervention\Image\Size;
7 
8 class FitCommand extends ResizeCommand
9 {
16  public function execute($image)
17  {
18  $width = $this->argument(0)->type('digit')->required()->value();
19  $height = $this->argument(1)->type('digit')->value($width);
20  $constraints = $this->argument(2)->type('closure')->value();
21  $position = $this->argument(3)->type('string')->value('center');
22 
23  // calculate size
24  $cropped = $image->getSize()->fit(new Size($width, $height), $position);
25  $resized = clone $cropped;
26  $resized = $resized->resize($width, $height, $constraints);
27 
28  // modify image
29  $this->modify($image, 0, 0, $cropped->pivot->x, $cropped->pivot->y, $resized->getWidth(), $resized->getHeight(), $cropped->getWidth(), $cropped->getHeight());
30 
31  return true;
32  }
33 }
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
php
Intervention\Image\Gd\Commands\FitCommand
Definition: FitCommand.php:9
Intervention\Image\Gd\Commands\FitCommand\execute
execute($image)
Definition: FitCommand.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