File indexing completed on 2025-01-26 05:29:14
0001 <?php 0002 0003 namespace Intervention\Image\Gd\Commands; 0004 0005 use Intervention\Image\Size; 0006 0007 class FitCommand extends ResizeCommand 0008 { 0009 /** 0010 * Crops and resized an image at the same time 0011 * 0012 * @param \Intervention\Image\Image $image 0013 * @return boolean 0014 */ 0015 public function execute($image) 0016 { 0017 $width = $this->argument(0)->type('digit')->required()->value(); 0018 $height = $this->argument(1)->type('digit')->value($width); 0019 $constraints = $this->argument(2)->type('closure')->value(); 0020 $position = $this->argument(3)->type('string')->value('center'); 0021 0022 // calculate size 0023 $cropped = $image->getSize()->fit(new Size($width, $height), $position); 0024 $resized = clone $cropped; 0025 $resized = $resized->resize($width, $height, $constraints); 0026 0027 // modify image 0028 $this->modify($image, 0, 0, $cropped->pivot->x, $cropped->pivot->y, $resized->getWidth(), $resized->getHeight(), $cropped->getWidth(), $cropped->getHeight()); 0029 0030 return true; 0031 } 0032 }