From 8c7fb0cb46649f14ff072dc29a5048a746a75f3b Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Wed, 6 Dec 2023 16:11:29 +0100 Subject: [PATCH] Fix bugs --- .../Imagick/Modifiers/ContainModifier.php | 22 ++++++++++++++----- src/Geometry/Rectangle.php | 12 +++++----- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/Drivers/Imagick/Modifiers/ContainModifier.php b/src/Drivers/Imagick/Modifiers/ContainModifier.php index 6ae581ce..a39eea4a 100644 --- a/src/Drivers/Imagick/Modifiers/ContainModifier.php +++ b/src/Drivers/Imagick/Modifiers/ContainModifier.php @@ -47,20 +47,25 @@ class ContainModifier extends DriverSpecializedModifier // fill new emerged background $draw = new ImagickDraw(); $draw->setFillColor($background); - if ($crop->pivot()->x() > 0) { + + $delta = abs($crop->pivot()->x()); + + if ($delta > 0) { $draw->rectangle( 0, 0, - $crop->pivot()->x(), + $delta - 1, $resize->height() ); } + $draw->rectangle( - $crop->pivot()->x() + $crop->width(), + $crop->width() + $delta, 0, $resize->width(), $resize->height() ); + $frame->native()->drawImage($draw); } @@ -68,20 +73,25 @@ class ContainModifier extends DriverSpecializedModifier // fill new emerged background $draw = new ImagickDraw(); $draw->setFillColor($background); - if ($crop->pivot()->y() > 0) { + + $delta = abs($crop->pivot()->y()); + + if ($delta > 0) { $draw->rectangle( 0, 0, $resize->width(), - $crop->pivot()->y(), + $delta - 1 ); } + $draw->rectangle( 0, - $crop->pivot()->y() + $crop->height(), + $crop->height() + $delta, $resize->width(), $resize->height() ); + $frame->native()->drawImage($draw); } } diff --git a/src/Geometry/Rectangle.php b/src/Geometry/Rectangle.php index 1fc3f140..31bbaa37 100644 --- a/src/Geometry/Rectangle.php +++ b/src/Geometry/Rectangle.php @@ -61,7 +61,7 @@ class Rectangle extends Polygon implements SizeInterface, DrawableInterface case 'top-middle': case 'center-top': case 'middle-top': - $x = intval($this->width() / 2) + $offset_x; + $x = intval(round($this->width() / 2)) + $offset_x; $y = 0 + $offset_y; break; @@ -77,7 +77,7 @@ class Rectangle extends Polygon implements SizeInterface, DrawableInterface case 'center-left': case 'middle-left': $x = 0 + $offset_x; - $y = intval($this->height() / 2) + $offset_y; + $y = intval(round($this->height() / 2)) + $offset_y; break; case 'right': @@ -86,7 +86,7 @@ class Rectangle extends Polygon implements SizeInterface, DrawableInterface case 'center-right': case 'middle-right': $x = $this->width() - $offset_x; - $y = intval($this->height() / 2) + $offset_y; + $y = intval(round($this->height() / 2)) + $offset_y; break; case 'bottom-left': @@ -100,7 +100,7 @@ class Rectangle extends Polygon implements SizeInterface, DrawableInterface case 'bottom-middle': case 'center-bottom': case 'middle-bottom': - $x = intval($this->width() / 2) + $offset_x; + $x = intval(round($this->width() / 2)) + $offset_x; $y = $this->height() - $offset_y; break; @@ -114,8 +114,8 @@ class Rectangle extends Polygon implements SizeInterface, DrawableInterface case 'middle': case 'center-center': case 'middle-middle': - $x = intval($this->width() / 2) + $offset_x; - $y = intval($this->height() / 2) + $offset_y; + $x = intval(round($this->width() / 2)) + $offset_x; + $y = intval(round($this->height() / 2)) + $offset_y; break; default: