From ec52b1f569a356eb584704215f8deeba58b885d1 Mon Sep 17 00:00:00 2001 From: ncla Date: Sun, 12 Feb 2023 13:30:29 +0200 Subject: [PATCH 1/2] Run resize on an image when crop zoom has been changed but the output dimensions match the original image --- src/Manipulators/Size.php | 2 +- tests/Manipulators/SizeTest.php | 47 +++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/Manipulators/Size.php b/src/Manipulators/Size.php index 19082642..0abc440e 100644 --- a/src/Manipulators/Size.php +++ b/src/Manipulators/Size.php @@ -67,7 +67,7 @@ public function run(Image $image) list($width, $height) = $this->applyDpr($width, $height, $dpr); list($width, $height) = $this->limitImageSize($width, $height); - if ((int) $width !== (int) $image->width() or (int) $height !== (int) $image->height()) { + if ((int) $width !== (int) $image->width() || (int) $height !== (int) $image->height() || $this->getCrop()[2] !== 1.0) { $image = $this->runResize($image, $fit, (int) $width, (int) $height); } diff --git a/tests/Manipulators/SizeTest.php b/tests/Manipulators/SizeTest.php index 2ffd5c2e..6ac3947d 100644 --- a/tests/Manipulators/SizeTest.php +++ b/tests/Manipulators/SizeTest.php @@ -249,4 +249,51 @@ public function testRunCropResize() $this->manipulator->runCropResize($image, 100, 100, 'center') ); } + + public function testResizeDoesNotRunWhenNoParamsAreSet() + { + $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $mock->shouldReceive('width')->andReturn(100)->twice(); + $mock->shouldReceive('height')->andReturn(100)->twice(); + $mock->shouldReceive('resize')->never(); + }); + + $this->assertInstanceOf( + 'Intervention\Image\Image', + $this->manipulator->run($image) + ); + } + + public function testResizeDoesNotRunWhenSettingFitCropToCenterWithNoZoom() + { + $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $mock->shouldReceive('width')->andReturn(100)->twice(); + $mock->shouldReceive('height')->andReturn(100)->twice(); + $mock->shouldReceive('resize')->never(); + }); + + $this->manipulator->setParams(['fit' => 'crop-50-50-1']); + + $this->assertInstanceOf( + 'Intervention\Image\Image', + $this->manipulator->run($image) + ); + } + + public function testResizeDoesRunWhenDimensionsAreTheSameAndTheCropZoomIsNotDefaultOne() + { + $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $mock->shouldReceive('width')->andReturn(100); + $mock->shouldReceive('height')->andReturn(100); + $mock->shouldReceive('resize')->once(); + $mock->shouldReceive('crop')->once()->andReturn($mock); + }); + + $this->manipulator->setParams(['fit' => 'crop-50-50-3.2']); + + $this->assertInstanceOf( + 'Intervention\Image\Image', + $this->manipulator->run($image) + ); + } } From af9919625d1e2900b4791d1b0480ceda68a89868 Mon Sep 17 00:00:00 2001 From: ncla Date: Sun, 12 Feb 2023 14:16:55 +0200 Subject: [PATCH 2/2] Style fix --- src/Manipulators/Size.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Manipulators/Size.php b/src/Manipulators/Size.php index 0abc440e..f6a6c815 100644 --- a/src/Manipulators/Size.php +++ b/src/Manipulators/Size.php @@ -67,7 +67,7 @@ public function run(Image $image) list($width, $height) = $this->applyDpr($width, $height, $dpr); list($width, $height) = $this->limitImageSize($width, $height); - if ((int) $width !== (int) $image->width() || (int) $height !== (int) $image->height() || $this->getCrop()[2] !== 1.0) { + if ((int) $width !== (int) $image->width() || (int) $height !== (int) $image->height() || 1.0 !== $this->getCrop()[2]) { $image = $this->runResize($image, $fit, (int) $width, (int) $height); }