From 3b7238f7a868fdf25c50504f3e6ac1f1e380e441 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Thu, 7 Dec 2023 18:37:50 +0100 Subject: [PATCH] Revert position behaviour of resize methods --- src/Interfaces/ImageInterface.php | 6 +++--- src/Modifiers/ContainModifier.php | 12 +----------- src/Modifiers/PadModifier.php | 2 +- src/Modifiers/ResizeCanvasModifier.php | 12 +----------- src/Modifiers/ResizeCanvasRelativeModifier.php | 2 +- .../Gd/Modifiers/ResizeCanvasModifierTest.php | 2 +- .../Imagick/Modifiers/ResizeCanvasModifierTest.php | 2 +- 7 files changed, 9 insertions(+), 29 deletions(-) diff --git a/src/Interfaces/ImageInterface.php b/src/Interfaces/ImageInterface.php index 7f8ca80a..99dd1a9c 100644 --- a/src/Interfaces/ImageInterface.php +++ b/src/Interfaces/ImageInterface.php @@ -349,9 +349,9 @@ public function coverDown(int $width, int $height, string $position = 'center'): /** * Resize the boundaries of the current image to given width and height. - * An anchor position can be defined to determine from what point of the - * image the resizing is going to happen. A background color can be passed - * to define the color of the new emerging areas. + * An anchor position can be defined to determine where the original image + * is fixed. A background color can be passed to define the color of the + * new emerging areas. * * @param null|int $width * @param null|int $height diff --git a/src/Modifiers/ContainModifier.php b/src/Modifiers/ContainModifier.php index e4a4ee50..cd3bc203 100644 --- a/src/Modifiers/ContainModifier.php +++ b/src/Modifiers/ContainModifier.php @@ -25,7 +25,7 @@ public function getCropSize(ImageInterface $image): SizeInterface ) ->alignPivotTo( $this->getResizeSize($image), - $this->position() + $this->position ); } @@ -33,14 +33,4 @@ public function getResizeSize(ImageInterface $image): SizeInterface { return new Rectangle($this->width, $this->height); } - - protected function position(): string - { - return strtr($this->position, [ - 'left' => 'right', - 'right' => 'left', - 'top' => 'bottom', - 'bottom' => 'top', - ]); - } } diff --git a/src/Modifiers/PadModifier.php b/src/Modifiers/PadModifier.php index 24bd9338..ee1e2e16 100644 --- a/src/Modifiers/PadModifier.php +++ b/src/Modifiers/PadModifier.php @@ -16,7 +16,7 @@ public function getCropSize(ImageInterface $image): SizeInterface ) ->alignPivotTo( $this->getResizeSize($image), - $this->position() + $this->position ); } } diff --git a/src/Modifiers/ResizeCanvasModifier.php b/src/Modifiers/ResizeCanvasModifier.php index 856739df..849640d3 100644 --- a/src/Modifiers/ResizeCanvasModifier.php +++ b/src/Modifiers/ResizeCanvasModifier.php @@ -24,17 +24,7 @@ public function cropSize(ImageInterface $image): SizeInterface return (new Rectangle($width, $height)) ->alignPivotTo( $image->size(), - $this->position() + $this->position ); } - - protected function position(): string - { - return strtr($this->position, [ - 'left' => 'right', - 'right' => 'left', - 'top' => 'bottom', - 'bottom' => 'top', - ]); - } } diff --git a/src/Modifiers/ResizeCanvasRelativeModifier.php b/src/Modifiers/ResizeCanvasRelativeModifier.php index 219e862f..eb11746c 100644 --- a/src/Modifiers/ResizeCanvasRelativeModifier.php +++ b/src/Modifiers/ResizeCanvasRelativeModifier.php @@ -16,7 +16,7 @@ public function cropSize(ImageInterface $image): SizeInterface return (new Rectangle($width, $height)) ->alignPivotTo( $image->size(), - $this->position() + $this->position ); } } diff --git a/tests/Drivers/Gd/Modifiers/ResizeCanvasModifierTest.php b/tests/Drivers/Gd/Modifiers/ResizeCanvasModifierTest.php index 6632b1d3..000a8b66 100644 --- a/tests/Drivers/Gd/Modifiers/ResizeCanvasModifierTest.php +++ b/tests/Drivers/Gd/Modifiers/ResizeCanvasModifierTest.php @@ -46,7 +46,7 @@ public function testModifyEdge(): void { $image = $this->createTestImage(1, 1); $this->assertColor(255, 0, 0, 255, $image->pickColor(0, 0)); - $image->modify(new ResizeCanvasModifier(null, 2, 'ff0', 'top')); + $image->modify(new ResizeCanvasModifier(null, 2, 'ff0', 'bottom')); $this->assertEquals(1, $image->width()); $this->assertEquals(2, $image->height()); $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); diff --git a/tests/Drivers/Imagick/Modifiers/ResizeCanvasModifierTest.php b/tests/Drivers/Imagick/Modifiers/ResizeCanvasModifierTest.php index 216c450d..a7ab3edb 100644 --- a/tests/Drivers/Imagick/Modifiers/ResizeCanvasModifierTest.php +++ b/tests/Drivers/Imagick/Modifiers/ResizeCanvasModifierTest.php @@ -46,7 +46,7 @@ public function testModifyEdge(): void { $image = $this->createTestImage(1, 1); $this->assertColor(255, 0, 0, 255, $image->pickColor(0, 0)); - $image->modify(new ResizeCanvasModifier(null, 2, 'ff0', 'top')); + $image->modify(new ResizeCanvasModifier(null, 2, 'ff0', 'bottom')); $this->assertEquals(1, $image->width()); $this->assertEquals(2, $image->height()); $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0));