diff --git a/src/Geometry/Tools/RectangleResizer.php b/src/Geometry/Tools/RectangleResizer.php index 38292da1..935e1af4 100644 --- a/src/Geometry/Tools/RectangleResizer.php +++ b/src/Geometry/Tools/RectangleResizer.php @@ -77,7 +77,7 @@ class RectangleResizer return $size->width(); } - return (int) round($this->height * $size->aspectRatio()); + return max([1, (int) round($this->height * $size->aspectRatio())]); } protected function getProportionalHeight(SizeInterface $size): int @@ -86,7 +86,7 @@ class RectangleResizer return $size->height(); } - return (int) round($this->width / $size->aspectRatio()); + return max([1, (int) round($this->width / $size->aspectRatio())]); } public function resize(SizeInterface $size): SizeInterface diff --git a/tests/Geometry/RectangleResizerTest.php b/tests/Geometry/RectangleResizerTest.php index bcc569b4..fe7ce1fd 100644 --- a/tests/Geometry/RectangleResizerTest.php +++ b/tests/Geometry/RectangleResizerTest.php @@ -269,6 +269,13 @@ class RectangleResizerTest extends TestCase $result = $resizer->scale($size); $this->assertEquals(4000, $result->width()); $this->assertEquals(2000, $result->height()); + + $size = new Rectangle(3, 3000); + $resizer = new RectangleResizer(); + $resizer->toHeight(300); + $result = $resizer->scale($size); + $this->assertEquals(1, $result->width()); + $this->assertEquals(300, $result->height()); } public function testScaleDown() @@ -363,6 +370,13 @@ class RectangleResizerTest extends TestCase $result = $resizer->scaleDown($size); $this->assertEquals(13, $result->width()); $this->assertEquals(10, $result->height()); + + $size = new Rectangle(3, 3000); + $resizer = new RectangleResizer(); + $resizer->toHeight(300); + $result = $resizer->scale($size); + $this->assertEquals(1, $result->width()); + $this->assertEquals(300, $result->height()); } /**