diff --git a/src/Manipulators/Size.php b/src/Manipulators/Size.php index 405d8c64..82ac92da 100644 --- a/src/Manipulators/Size.php +++ b/src/Manipulators/Size.php @@ -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 [ diff --git a/tests/Manipulators/SizeTest.php b/tests/Manipulators/SizeTest.php index 104ce4ab..2ffd5c2e 100644 --- a/tests/Manipulators/SizeTest.php +++ b/tests/Manipulators/SizeTest.php @@ -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));