1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-29 08:40:33 +02:00

Limit proportional sclaing values to a min. of 1

This commit is contained in:
Oliver Vogel
2024-01-02 12:51:33 +01:00
parent 3f96a8f752
commit 66b2895238
2 changed files with 16 additions and 2 deletions

View File

@@ -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

View File

@@ -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());
}
/**