mirror of
https://github.com/Intervention/image.git
synced 2025-08-13 17:34:04 +02:00
Merge branch 'develop' into feature/better-input-handler
This commit is contained in:
12
.github/ISSUE_TEMPLATE/feature_request.md
vendored
12
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@@ -7,14 +7,8 @@ assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
**Describe the feature you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
@@ -12,7 +12,17 @@ class RectangleResizer
|
||||
protected ?int $width = null,
|
||||
protected ?int $height = null,
|
||||
) {
|
||||
//
|
||||
if (is_int($width) && $width < 1) {
|
||||
throw new GeometryException(
|
||||
'The width you specify must be greater than or equal to 1.'
|
||||
);
|
||||
}
|
||||
|
||||
if (is_int($height) && $height < 1) {
|
||||
throw new GeometryException(
|
||||
'The height you specify must be greater than or equal to 1.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static function to(...$arguments): self
|
||||
@@ -77,7 +87,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 +96,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
|
||||
|
@@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user