Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Jan 11, 2025
1 parent c333b92 commit 8cfbd65
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Drivers/Imagick/Modifiers/CropModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function apply(ImageInterface $image): ImageInterface
// place original frame content onto the empty colored frame canvas
$canvas->compositeImage(
$frame->native(),
Imagick::COMPOSITE_OVER,
Imagick::COMPOSITE_DEFAULT,
($crop->pivot()->x() + $this->offset_x) * -1,
($crop->pivot()->y() + $this->offset_y) * -1,
);
Expand Down
1 change: 1 addition & 0 deletions tests/ImagickTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static function createTestImage(int $width, int $height): Image
$imagick->setImageType(Imagick::IMGTYPE_UNDEFINED);
$imagick->setColorspace(Imagick::COLORSPACE_SRGB);
$imagick->setImageResolution(96, 96);
$imagick->setImageBackgroundColor($background);

return new Image(
new Driver(),
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 @@ -66,4 +66,21 @@ public function testModifyKeepsResolution(): void
$image = $image->modify(new CropModifier(800, 100, -10, -10, 'ff0000'));
$this->assertEquals(300, round($image->resolution()->perInch()->x()));
}

public function testHalfTransparent(): void
{
$image = $this->createTestImage(16, 16);
$image->modify(new CropModifier(32, 32, 0, 0, '00f5', 'center'));
$this->assertEquals(32, $image->width());
$this->assertEquals(32, $image->height());
$this->assertColor(0, 0, 255, 77, $image->pickColor(5, 5));
$this->assertColor(0, 0, 255, 77, $image->pickColor(16, 5));
$this->assertColor(0, 0, 255, 77, $image->pickColor(30, 5));
$this->assertColor(0, 0, 255, 77, $image->pickColor(5, 16));
$this->assertColor(255, 0, 0, 255, $image->pickColor(16, 16));
$this->assertColor(0, 0, 255, 77, $image->pickColor(30, 16));
$this->assertColor(0, 0, 255, 77, $image->pickColor(5, 30));
$this->assertColor(0, 0, 255, 77, $image->pickColor(16, 30));
$this->assertColor(0, 0, 255, 77, $image->pickColor(30, 30));
}
}

0 comments on commit 8cfbd65

Please sign in to comment.