mirror of
https://github.com/Intervention/image.git
synced 2025-09-02 10:23:29 +02:00
Limit proportional sclaing values to a min. of 1
This commit is contained in:
@@ -77,7 +77,7 @@ class RectangleResizer
|
|||||||
return $size->width();
|
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
|
protected function getProportionalHeight(SizeInterface $size): int
|
||||||
@@ -86,7 +86,7 @@ class RectangleResizer
|
|||||||
return $size->height();
|
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
|
public function resize(SizeInterface $size): SizeInterface
|
||||||
|
@@ -269,6 +269,13 @@ class RectangleResizerTest extends TestCase
|
|||||||
$result = $resizer->scale($size);
|
$result = $resizer->scale($size);
|
||||||
$this->assertEquals(4000, $result->width());
|
$this->assertEquals(4000, $result->width());
|
||||||
$this->assertEquals(2000, $result->height());
|
$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()
|
public function testScaleDown()
|
||||||
@@ -363,6 +370,13 @@ class RectangleResizerTest extends TestCase
|
|||||||
$result = $resizer->scaleDown($size);
|
$result = $resizer->scaleDown($size);
|
||||||
$this->assertEquals(13, $result->width());
|
$this->assertEquals(13, $result->width());
|
||||||
$this->assertEquals(10, $result->height());
|
$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