Skip to content

Commit

Permalink
Merge pull request #321 from nlemoine/1.x
Browse files Browse the repository at this point in the history
Fix rounding issue
  • Loading branch information
ADmad authored May 20, 2021
2 parents 13c3f94 + 0116ce6 commit 753bc82
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Manipulators/Size.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,14 @@ public function resolveMissingDimensions(Image $image, $width, $height)
$height = $image->height();
}

if (is_null($width)) {
$width = $height * ($image->width() / $image->height());
}

if (is_null($height)) {
$height = $width / ($image->width() / $image->height());
if (is_null($width) || is_null($height)) {
$size = (new \Intervention\Image\Size($image->width(), $image->height()))
->resize($width, $height, function ($constraint) {
$constraint->aspectRatio();
});

$width = $size->getWidth();
$height = $size->getHeight();
}

return [
Expand Down
10 changes: 10 additions & 0 deletions tests/Manipulators/SizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ public function testResolveMissingDimensions()
$this->assertSame([200, 100], $this->manipulator->resolveMissingDimensions($image, null, 100));
}

public function testResolveMissingDimensionsWithOddDimensions()
{
$image = Mockery::mock('Intervention\Image\Image', function ($mock) {
$mock->shouldReceive('width')->andReturn(1024);
$mock->shouldReceive('height')->andReturn(553);
});

$this->assertSame([411, 222], $this->manipulator->resolveMissingDimensions($image, 411, null));
}

public function testLimitImageSize()
{
$this->assertSame([1000, 1000], $this->manipulator->limitImageSize(1000, 1000));
Expand Down

0 comments on commit 753bc82

Please sign in to comment.