From ba7fc0e42e8e885aea94e6576817521ba70d6668 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Thu, 11 Nov 2021 14:16:28 +0000 Subject: [PATCH] pad & padDown --- src/Drivers/Abstract/AbstractImage.php | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/Drivers/Abstract/AbstractImage.php b/src/Drivers/Abstract/AbstractImage.php index 9949a07f..23637795 100644 --- a/src/Drivers/Abstract/AbstractImage.php +++ b/src/Drivers/Abstract/AbstractImage.php @@ -211,6 +211,44 @@ abstract class AbstractImage ); } + public function pad(int $width, int $height, string $position = 'center'): ImageInterface + { + $imagesize = $this->getSize(); + + // crop + $crop = new Size($width, $height); + $crop = $crop->cover($imagesize)->alignPivotTo( + $imagesize->alignPivot($position), + $position + ); + + // resize + $resize = $crop->scale($width, $height); + + return $this->modify( + $this->resolveDriverClass('Modifiers\CropResizeModifier', $crop, $resize, $position) + ); + } + + public function padDown(int $width, int $height, string $position = 'center'): ImageInterface + { + $imagesize = $this->getSize(); + + // crop + $crop = new Size($width, $height); + $crop = $crop->cover($imagesize)->alignPivotTo( + $imagesize->alignPivot($position), + $position + ); + + // resize + $resize = $crop->scaleDown($width, $height); + + return $this->modify( + $this->resolveDriverClass('Modifiers\CropResizeModifier', $crop, $resize, $position) + ); + } + public function place($element, string $position = 'top-left', int $offset_x = 0, int $offset_y = 0): ImageInterface { return $this->modify(