Skip to content

Commit

Permalink
Correct cropping with ImageMagick
Browse files Browse the repository at this point in the history
The crop was missing the apropriate resizing operation. The test didn't
catch it because it used the same height as the original.
  • Loading branch information
splitbrain committed Feb 4, 2022
1 parent c311230 commit be0785c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/ImageMagickAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,14 @@ public function crop($width, $height)
if ($width == 0) $width = $height;
if ($height == 0) $height = $width;

$size = $width . 'x' . $height;

$this->args[] = '-resize';
$this->args[] = "$size^";
$this->args[] = '-gravity';
$this->args[] = 'center';
$this->args[] = '-crop';
$this->args[] = $width . 'x' . $height . '+0+0';
$this->args[] = "$size+0+0";
$this->args[] = '+repage';
return $this;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/BaseAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ public function testCrop()
$this->assertSize($orig, 1000, 500);

($this->getAdapter($orig))
->crop(500, 500)
->crop(250, 250)
->save($dest);

$this->assertSize($dest, 500, 500);
$this->assertSize($dest, 250, 250);
$this->assertColor($dest, 'top', 'blue');
$this->assertColor($dest, 'bottom', 'green');
$this->assertAlpha($dest, 'center', 100);
Expand Down

0 comments on commit be0785c

Please sign in to comment.