diff --git a/src/Drivers/Gd/Modifiers/PadModifier.php b/src/Drivers/Gd/Modifiers/PadModifier.php index 73e11b4af..52a6acb03 100644 --- a/src/Drivers/Gd/Modifiers/PadModifier.php +++ b/src/Drivers/Gd/Modifiers/PadModifier.php @@ -4,6 +4,21 @@ namespace Intervention\Image\Drivers\Gd\Modifiers; +use Intervention\Image\Interfaces\ImageInterface; +use Intervention\Image\Interfaces\SizeInterface; + class PadModifier extends ContainModifier { + public function getCropSize(ImageInterface $image): SizeInterface + { + return $image->size() + ->containMax( + $this->width, + $this->height + ) + ->alignPivotTo( + $this->getResizeSize($image), + $this->position + ); + } } diff --git a/src/Drivers/Imagick/Modifiers/PadModifier.php b/src/Drivers/Imagick/Modifiers/PadModifier.php index d924ae160..40499d91f 100644 --- a/src/Drivers/Imagick/Modifiers/PadModifier.php +++ b/src/Drivers/Imagick/Modifiers/PadModifier.php @@ -4,6 +4,21 @@ namespace Intervention\Image\Drivers\Imagick\Modifiers; +use Intervention\Image\Interfaces\ImageInterface; +use Intervention\Image\Interfaces\SizeInterface; + class PadModifier extends ContainModifier { + public function getCropSize(ImageInterface $image): SizeInterface + { + return $image->size() + ->containMax( + $this->width, + $this->height + ) + ->alignPivotTo( + $this->getResizeSize($image), + $this->position + ); + } } diff --git a/tests/Unit/Drivers/Gd/Modifiers/PadModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/PadModifierTest.php new file mode 100644 index 000000000..feb4e4a43 --- /dev/null +++ b/tests/Unit/Drivers/Gd/Modifiers/PadModifierTest.php @@ -0,0 +1,42 @@ +readTestImage('blue.gif'); + $this->assertEquals(16, $image->width()); + $this->assertEquals(16, $image->height()); + $image->modify(new PadModifier(30, 20, 'f00')); + $this->assertEquals(30, $image->width()); + $this->assertEquals(20, $image->height()); + $this->assertColor(255, 0, 0, 255, $image->pickColor(0, 0)); + $this->assertColor(255, 0, 0, 255, $image->pickColor(0, 19)); + $this->assertColor(255, 0, 0, 255, $image->pickColor(29, 0)); + $this->assertColor(255, 0, 0, 255, $image->pickColor(29, 19)); + $this->assertColor(255, 0, 0, 255, $image->pickColor(6, 2)); + $this->assertColor(255, 0, 0, 255, $image->pickColor(7, 1)); + $this->assertColor(255, 0, 0, 255, $image->pickColor(6, 17)); + $this->assertColor(255, 0, 0, 255, $image->pickColor(7, 18)); + $this->assertColor(255, 0, 0, 255, $image->pickColor(23, 1)); + $this->assertColor(255, 0, 0, 255, $image->pickColor(23, 2)); + $this->assertColor(255, 0, 0, 255, $image->pickColor(23, 17)); + $this->assertColor(255, 0, 0, 255, $image->pickColor(23, 18)); + $this->assertColor(100, 100, 255, 255, $image->pickColor(7, 2)); + $this->assertColor(100, 100, 255, 255, $image->pickColor(22, 2)); + $this->assertColor(100, 100, 255, 255, $image->pickColor(7, 17)); + $this->assertColor(100, 100, 255, 255, $image->pickColor(22, 17)); + } +} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/PadModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/PadModifierTest.php new file mode 100644 index 000000000..620a4d058 --- /dev/null +++ b/tests/Unit/Drivers/Imagick/Modifiers/PadModifierTest.php @@ -0,0 +1,42 @@ +readTestImage('blue.gif'); + $this->assertEquals(16, $image->width()); + $this->assertEquals(16, $image->height()); + $image->modify(new PadModifier(30, 20, 'f00')); + $this->assertEquals(30, $image->width()); + $this->assertEquals(20, $image->height()); + $this->assertColor(255, 0, 0, 255, $image->pickColor(0, 0)); + $this->assertColor(255, 0, 0, 255, $image->pickColor(0, 19)); + $this->assertColor(255, 0, 0, 255, $image->pickColor(29, 0)); + $this->assertColor(255, 0, 0, 255, $image->pickColor(29, 19)); + $this->assertColor(255, 0, 0, 255, $image->pickColor(6, 2)); + $this->assertColor(255, 0, 0, 255, $image->pickColor(7, 1)); + $this->assertColor(255, 0, 0, 255, $image->pickColor(6, 17)); + $this->assertColor(255, 0, 0, 255, $image->pickColor(7, 18)); + $this->assertColor(255, 0, 0, 255, $image->pickColor(23, 1)); + $this->assertColor(255, 0, 0, 255, $image->pickColor(23, 2)); + $this->assertColor(255, 0, 0, 255, $image->pickColor(23, 17)); + $this->assertColor(255, 0, 0, 255, $image->pickColor(23, 18)); + $this->assertColor(100, 100, 255, 255, $image->pickColor(7, 2)); + $this->assertColor(100, 100, 255, 255, $image->pickColor(22, 2)); + $this->assertColor(100, 100, 255, 255, $image->pickColor(7, 17)); + $this->assertColor(100, 100, 255, 255, $image->pickColor(22, 17)); + } +}