File indexing completed on 2025-01-26 05:29:14
0001 <?php 0002 0003 namespace Intervention\Image\Imagick\Commands; 0004 0005 use Intervention\Image\Point; 0006 use Intervention\Image\Size; 0007 0008 class CropCommand extends \Intervention\Image\Commands\AbstractCommand 0009 { 0010 /** 0011 * Crop an image instance 0012 * 0013 * @param \Intervention\Image\Image $image 0014 * @return boolean 0015 */ 0016 public function execute($image) 0017 { 0018 $width = $this->argument(0)->type('digit')->required()->value(); 0019 $height = $this->argument(1)->type('digit')->required()->value(); 0020 $x = $this->argument(2)->type('digit')->value(); 0021 $y = $this->argument(3)->type('digit')->value(); 0022 0023 if (is_null($width) || is_null($height)) { 0024 throw new \Intervention\Image\Exception\InvalidArgumentException( 0025 "Width and height of cutout needs to be defined." 0026 ); 0027 } 0028 0029 $cropped = new Size($width, $height); 0030 $position = new Point($x, $y); 0031 0032 // align boxes 0033 if (is_null($x) && is_null($y)) { 0034 $position = $image->getSize()->align('center')->relativePosition($cropped->align('center')); 0035 } 0036 0037 // crop image core 0038 $image->getCore()->cropImage($cropped->width, $cropped->height, $position->x, $position->y); 0039 $image->getCore()->setImagePage(0,0,0,0); 0040 0041 return true; 0042 } 0043 }