Skip to content

Commit

Permalink
Merge pull request #364 from ncla/fix/issue-362-v1
Browse files Browse the repository at this point in the history
[1.x] Do run resize operation on an image when crop zoom has changed
  • Loading branch information
ADmad committed Feb 14, 2023
2 parents 257e0c3 + af99196 commit 8dba756
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Manipulators/Size.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() || 1.0 !== $this->getCrop()[2]) {
$image = $this->runResize($image, $fit, (int) $width, (int) $height);
}

Expand Down
47 changes: 47 additions & 0 deletions tests/Manipulators/SizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
}

0 comments on commit 8dba756

Please sign in to comment.