diff --git a/src/Image.php b/src/Image.php index 379e2925d..6601b21a6 100644 --- a/src/Image.php +++ b/src/Image.php @@ -537,11 +537,16 @@ public function resizeCanvas( 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 658ea1771..7f8ca80a7 100644 --- a/src/Interfaces/ImageInterface.php +++ b/src/Interfaces/ImageInterface.php @@ -403,7 +403,7 @@ public function pad( int $width, int $height, mixed $background = 'ffffff', - string $position = 'center', + string $position = 'center' ): ImageInterface; /** @@ -420,7 +420,7 @@ public function contain( int $width, int $height, mixed $background = 'ffffff', - string $position = 'center', + string $position = 'center' ): ImageInterface; /** @@ -440,7 +440,7 @@ public function crop( 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 ce98dafad..e4a4ee507 100644 --- a/src/Modifiers/ContainModifier.php +++ b/src/Modifiers/ContainModifier.php @@ -19,12 +19,28 @@ public function __construct( 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 7cf1f9866..24bd9338e 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 7bd7695e1..856739dfd 100644 --- a/src/Modifiers/ResizeCanvasModifier.php +++ b/src/Modifiers/ResizeCanvasModifier.php @@ -22,7 +22,10 @@ public function cropSize(ImageInterface $image): SizeInterface $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 57d8834dd..219e862ff 100644 --- a/src/Modifiers/ResizeCanvasRelativeModifier.php +++ b/src/Modifiers/ResizeCanvasRelativeModifier.php @@ -14,6 +14,9 @@ public function cropSize(ImageInterface $image): SizeInterface $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() + ); } }