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