File indexing completed on 2025-01-26 05:29:14
0001 <?php 0002 0003 namespace Intervention\Image\Imagick\Commands; 0004 0005 use Intervention\Image\Size; 0006 0007 class FitCommand extends \Intervention\Image\Commands\AbstractCommand 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 // crop image 0028 $image->getCore()->cropImage( 0029 $cropped->width, 0030 $cropped->height, 0031 $cropped->pivot->x, 0032 $cropped->pivot->y 0033 ); 0034 0035 // resize image 0036 $image->getCore()->scaleImage($resized->getWidth(), $resized->getHeight()); 0037 $image->getCore()->setImagePage(0,0,0,0); 0038 0039 return true; 0040 } 0041 }