/**
  * Crop an image instance
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $width = $this->argument(0)->type('integer')->required()->value();
     $height = $this->argument(1)->type('integer')->required()->value();
     $x = $this->argument(2)->type('integer')->value();
     $y = $this->argument(3)->type('integer')->value();
     if (is_null($width) || is_null($height)) {
         throw new \Intervention\Image\Exception\InvalidArgumentException("Width and height of cutout needs to be defined.");
     }
     $cropped = new Size($width, $height);
     $position = new Point($x, $y);
     // align boxes
     if (is_null($x) && is_null($y)) {
         $position = $image->getSize()->align('center')->relativePosition($cropped->align('center'));
     }
     // crop image core
     return $this->modify($image, 0, 0, $position->x, $position->y, $cropped->width, $cropped->height, $cropped->width, $cropped->height);
 }
 public function testAlign()
 {
     $width = 640;
     $height = 480;
     $pivot = Mockery::mock('Intervention\\Image\\Point');
     $pivot->shouldReceive('setPosition')->with(0, 0)->once();
     $pivot->shouldReceive('setPosition')->with(intval($width / 2), 0)->once();
     $pivot->shouldReceive('setPosition')->with($width, 0)->once();
     $pivot->shouldReceive('setPosition')->with(0, intval($height / 2))->once();
     $pivot->shouldReceive('setPosition')->with(intval($width / 2), intval($height / 2))->once();
     $pivot->shouldReceive('setPosition')->with($width, intval($height / 2))->once();
     $pivot->shouldReceive('setPosition')->with(0, $height)->once();
     $pivot->shouldReceive('setPosition')->with(intval($width / 2), $height)->once();
     $pivot->shouldReceive('setPosition')->with($width, $height)->once();
     $box = new Size($width, $height, $pivot);
     $box->align('top-left');
     $box->align('top');
     $box->align('top-right');
     $box->align('left');
     $box->align('center');
     $box->align('right');
     $box->align('bottom-left');
     $box->align('bottom');
     $b = $box->align('bottom-right');
     $this->assertInstanceOf('Intervention\\Image\\Size', $b);
 }
Esempio n. 3
0
 public function testResizeCanvas()
 {
     $box = new Size(300, 200);
     $box->resizeCanvas(400, 500);
     $this->assertEquals(400, $box->width);
     $this->assertEquals(500, $box->height);
     $this->assertEquals(0, $box->pivot->x);
     $this->assertEquals(0, $box->pivot->y);
     $box = new Size(300, 200);
     $box->align('top');
     $box->resizeCanvas(50, 100, true);
     $this->assertEquals(400, $box->width);
     $this->assertEquals(400, $box->height);
     $this->assertEquals(200, $box->pivot->x);
     $this->assertEquals(0, $box->pivot->y);
     $box = new Size(300, 200);
     $box->align('center');
     $box->resizeCanvas(150, 120, true);
     $this->assertEquals(600, $box->width);
     $this->assertEquals(440, $box->height);
     $this->assertEquals(300, $box->pivot->x);
     $this->assertEquals(220, $box->pivot->y);
     $box = new Size(300, 200);
     $box->align('right');
     $box->resizeCanvas(300, 1000);
     $this->assertEquals(300, $box->width);
     $this->assertEquals(1000, $box->height);
     $this->assertEquals(300, $box->pivot->x);
     $this->assertEquals(500, $box->pivot->y);
     $box = new Size(300, 200);
     $box->align('right-bottom');
     $box->resizeCanvas(50, 100);
     $this->assertEquals(50, $box->width);
     $this->assertEquals(100, $box->height);
     $this->assertEquals(50, $box->pivot->x);
     $this->assertEquals(100, $box->pivot->y);
     $box = new Size(300, 200);
     $box->align('bottom');
     $box->resizeCanvas(50, 100);
     $this->assertEquals(50, $box->width);
     $this->assertEquals(100, $box->height);
     $this->assertEquals(25, $box->pivot->x);
     $this->assertEquals(100, $box->pivot->y);
 }