Skip to content

Commit

Permalink
Keep image resolutionin CropModifier::class
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Jan 10, 2025
1 parent 3ac8c67 commit f5027b2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Drivers/Imagick/Modifiers/CropModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ public function apply(ImageInterface $image): ImageInterface
);

$imagick = new Imagick();
$resolution = $image->resolution()->perInch();

foreach ($image as $frame) {
$canvas = new Imagick();
$canvas->newImage($crop->width(), $crop->height(), $background, 'png');
$canvas->setImageResolution($resolution->x(), $resolution->y());

$canvas->compositeImage(
$frame->native(),
Expand Down
17 changes: 17 additions & 0 deletions tests/Unit/Drivers/Imagick/Modifiers/CropModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers;

use Intervention\Image\Colors\Cmyk\Colorspace;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Modifiers\CropModifier;
Expand Down Expand Up @@ -36,4 +37,20 @@ public function testModifyExtend(): void
$this->assertColor(0, 0, 255, 255, $image->pickColor(445, 16));
$this->assertTransparency($image->pickColor(460, 16));
}

public function testModifyKeepsColorspace(): void
{
$image = $this->readTestImage('cmyk.jpg');
$this->assertInstanceOf(Colorspace::class, $image->colorspace());
$image = $image->modify(new CropModifier(800, 100, -10, -10, 'ff0000'));
$this->assertInstanceOf(Colorspace::class, $image->colorspace());
}

public function testModifyKeepsResolution(): void
{
$image = $this->readTestImage('300dpi.png');
$this->assertEquals(300, round($image->resolution()->perInch()->x()));
$image = $image->modify(new CropModifier(800, 100, -10, -10, 'ff0000'));
$this->assertEquals(300, round($image->resolution()->perInch()->x()));
}
}

0 comments on commit f5027b2

Please sign in to comment.