diff --git a/src/Drivers/Abstract/AbstractImage.php b/src/Drivers/Abstract/AbstractImage.php index 4d11c373..55c3be56 100644 --- a/src/Drivers/Abstract/AbstractImage.php +++ b/src/Drivers/Abstract/AbstractImage.php @@ -153,6 +153,30 @@ abstract class AbstractImage ); } + /** + * Creates a vertical mirror image + * + * @return ImageInterface + */ + public function flip(): ImageInterface + { + return $this->modify( + $this->resolveDriverClass('Modifiers\FlipModifier') + ); + } + + /** + * Creates a horizontal mirror image + * + * @return ImageInterface + */ + public function flop(): ImageInterface + { + return $this->modify( + $this->resolveDriverClass('Modifiers\FlopModifier') + ); + } + public function place($element, string $position = 'top-left', int $offset_x = 0, int $offset_y = 0): ImageInterface { return $this->modify( diff --git a/src/Drivers/Gd/Modifiers/FlipModifier.php b/src/Drivers/Gd/Modifiers/FlipModifier.php new file mode 100644 index 00000000..a7eee567 --- /dev/null +++ b/src/Drivers/Gd/Modifiers/FlipModifier.php @@ -0,0 +1,18 @@ +getCore(), IMG_FLIP_VERTICAL); + } + + return $image; + } +} diff --git a/src/Drivers/Gd/Modifiers/FlopModifier.php b/src/Drivers/Gd/Modifiers/FlopModifier.php new file mode 100644 index 00000000..e926e3e0 --- /dev/null +++ b/src/Drivers/Gd/Modifiers/FlopModifier.php @@ -0,0 +1,18 @@ +getCore(), IMG_FLIP_HORIZONTAL); + } + + return $image; + } +} diff --git a/src/Drivers/Imagick/Modifiers/FlipModifier.php b/src/Drivers/Imagick/Modifiers/FlipModifier.php new file mode 100644 index 00000000..1c916393 --- /dev/null +++ b/src/Drivers/Imagick/Modifiers/FlipModifier.php @@ -0,0 +1,18 @@ +getCore()->flipImage(); + } + + return $image; + } +} diff --git a/src/Drivers/Imagick/Modifiers/FlopModifier.php b/src/Drivers/Imagick/Modifiers/FlopModifier.php new file mode 100644 index 00000000..cfb7160d --- /dev/null +++ b/src/Drivers/Imagick/Modifiers/FlopModifier.php @@ -0,0 +1,18 @@ +getCore()->flopImage(); + } + + return $image; + } +} diff --git a/tests/Drivers/Gd/Modifiers/FlipFlopModifierTest.php b/tests/Drivers/Gd/Modifiers/FlipFlopModifierTest.php new file mode 100644 index 00000000..0305f6a8 --- /dev/null +++ b/tests/Drivers/Gd/Modifiers/FlipFlopModifierTest.php @@ -0,0 +1,34 @@ +createTestImage('tile.png'); + $this->assertEquals('b4e000', $image->pickColor(0, 0)->toHex()); + $image->modify(new FlipModifier()); + $this->assertEquals('000000', $image->pickColor(0, 0)->toHex()); + } + + public function testFlopImage(): void + { + $image = $this->createTestImage('tile.png'); + $this->assertEquals('b4e000', $image->pickColor(0, 0)->toHex()); + $image->modify(new FlopModifier()); + $this->assertEquals('000000', $image->pickColor(0, 0)->toHex()); + } +} diff --git a/tests/Drivers/Imagick/Modifiers/FlipFlopModifierTest.php b/tests/Drivers/Imagick/Modifiers/FlipFlopModifierTest.php new file mode 100644 index 00000000..10ecab69 --- /dev/null +++ b/tests/Drivers/Imagick/Modifiers/FlipFlopModifierTest.php @@ -0,0 +1,34 @@ +createTestImage('tile.png'); + $this->assertEquals('b4e000', $image->pickColor(0, 0)->toHex()); + $image->modify(new FlipModifier()); + $this->assertEquals('000000', $image->pickColor(0, 0)->toHex()); + } + + public function testFlopImage(): void + { + $image = $this->createTestImage('tile.png'); + $this->assertEquals('b4e000', $image->pickColor(0, 0)->toHex()); + $image->modify(new FlopModifier()); + $this->assertEquals('000000', $image->pickColor(0, 0)->toHex()); + } +}