diff --git a/src/Image.php b/src/Image.php index 379e2925..6601b21a 100644 --- a/src/Image.php +++ b/src/Image.php @@ -537,11 +537,16 @@ final class Image implements ImageInterface, Countable return $this->modify(new ResizeCanvasModifier($width, $height, $background, $position)); } + /** + * {@inheritdoc} + * + * @see ImageInterface::resizeCanvasRelative() + */ public function resizeCanvasRelative( ?int $width = null, ?int $height = null, mixed $background = 'ffffff', - string $position = 'center', + string $position = 'center' ): ImageInterface { return $this->modify(new ResizeCanvasRelativeModifier($width, $height, $background, $position)); } diff --git a/src/Interfaces/ImageInterface.php b/src/Interfaces/ImageInterface.php index 658ea177..7f8ca80a 100644 --- a/src/Interfaces/ImageInterface.php +++ b/src/Interfaces/ImageInterface.php @@ -403,7 +403,7 @@ interface ImageInterface extends IteratorAggregate, Countable int $width, int $height, mixed $background = 'ffffff', - string $position = 'center', + string $position = 'center' ): ImageInterface; /** @@ -420,7 +420,7 @@ interface ImageInterface extends IteratorAggregate, Countable int $width, int $height, mixed $background = 'ffffff', - string $position = 'center', + string $position = 'center' ): ImageInterface; /** @@ -440,7 +440,7 @@ interface ImageInterface extends IteratorAggregate, Countable int $height, int $offset_x = 0, int $offset_y = 0, - string $position = 'top-left', + string $position = 'top-left' ): ImageInterface; /** diff --git a/src/Modifiers/ContainModifier.php b/src/Modifiers/ContainModifier.php index ce98dafa..e4a4ee50 100644 --- a/src/Modifiers/ContainModifier.php +++ b/src/Modifiers/ContainModifier.php @@ -19,12 +19,28 @@ class ContainModifier extends AbstractModifier public function getCropSize(ImageInterface $image): SizeInterface { return $image->size() - ->contain($this->width, $this->height) - ->alignPivotTo($this->getResizeSize($image), $this->position); + ->contain( + $this->width, + $this->height + ) + ->alignPivotTo( + $this->getResizeSize($image), + $this->position() + ); } 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 7cf1f986..24bd9338 100644 --- a/src/Modifiers/PadModifier.php +++ b/src/Modifiers/PadModifier.php @@ -10,7 +10,13 @@ class PadModifier extends ContainModifier public function getCropSize(ImageInterface $image): SizeInterface { return $image->size() - ->containMax($this->width, $this->height) - ->alignPivotTo($this->getResizeSize($image), $this->position); + ->containMax( + $this->width, + $this->height + ) + ->alignPivotTo( + $this->getResizeSize($image), + $this->position() + ); } } diff --git a/src/Modifiers/ResizeCanvasModifier.php b/src/Modifiers/ResizeCanvasModifier.php index 7bd7695e..856739df 100644 --- a/src/Modifiers/ResizeCanvasModifier.php +++ b/src/Modifiers/ResizeCanvasModifier.php @@ -22,7 +22,10 @@ class ResizeCanvasModifier extends AbstractModifier $height = is_null($this->height) ? $image->height() : $this->height; return (new Rectangle($width, $height)) - ->alignPivotTo($image->size(), $this->position()); + ->alignPivotTo( + $image->size(), + $this->position() + ); } protected function position(): string diff --git a/src/Modifiers/ResizeCanvasRelativeModifier.php b/src/Modifiers/ResizeCanvasRelativeModifier.php index 57d8834d..219e862f 100644 --- a/src/Modifiers/ResizeCanvasRelativeModifier.php +++ b/src/Modifiers/ResizeCanvasRelativeModifier.php @@ -14,6 +14,9 @@ class ResizeCanvasRelativeModifier extends ResizeCanvasModifier $height = is_null($this->height) ? $image->height() : $image->height() + $this->height; return (new Rectangle($width, $height)) - ->alignPivotTo($image->size(), $this->position()); + ->alignPivotTo( + $image->size(), + $this->position() + ); } }