Skip to content

Commit a566769

Browse files
committed
Fix bug in cover modifiers
See: #1359
1 parent 193324e commit a566769

File tree

7 files changed

+95
-3
lines changed

7 files changed

+95
-3
lines changed

src/Drivers/Gd/Modifiers/CoverDownModifier.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ class CoverDownModifier extends CoverModifier
1414
*/
1515
public function getResizeSize(SizeInterface $size): SizeInterface
1616
{
17-
return $size->scaleDown($this->width, $this->height);
17+
return $size->resizeDown($this->width, $this->height);
1818
}
1919
}

src/Drivers/Imagick/Modifiers/CoverDownModifier.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ class CoverDownModifier extends CoverModifier
1414
*/
1515
public function getResizeSize(SizeInterface $size): SizeInterface
1616
{
17-
return $size->scaleDown($this->width, $this->height);
17+
return $size->resizeDown($this->width, $this->height);
1818
}
1919
}

src/Modifiers/CoverModifier.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ public function getCropSize(ImageInterface $image): SizeInterface
3838
*/
3939
public function getResizeSize(SizeInterface $size): SizeInterface
4040
{
41-
return $size->scale($this->width, $this->height);
41+
return $size->resize($this->width, $this->height);
4242
}
4343
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers;
6+
7+
use Intervention\Image\Drivers\Gd\Modifiers\CoverDownModifier;
8+
use PHPUnit\Framework\Attributes\CoversClass;
9+
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
10+
use Intervention\Image\Tests\GdTestCase;
11+
12+
#[RequiresPhpExtension('gd')]
13+
#[CoversClass(\Intervention\Image\Modifiers\CoverModifier::class)]
14+
#[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\CoverModifier::class)]
15+
final class CoverDownModifierTest extends GdTestCase
16+
{
17+
public function testModify(): void
18+
{
19+
$image = $this->readTestImage('blocks.png');
20+
$this->assertEquals(640, $image->width());
21+
$this->assertEquals(480, $image->height());
22+
$image->modify(new CoverDownModifier(100, 100, 'center'));
23+
$this->assertEquals(100, $image->width());
24+
$this->assertEquals(100, $image->height());
25+
$this->assertColor(255, 0, 0, 255, $image->pickColor(90, 90));
26+
$this->assertColor(0, 255, 0, 255, $image->pickColor(65, 70));
27+
$this->assertColor(0, 0, 255, 255, $image->pickColor(70, 52));
28+
$this->assertTransparency($image->pickColor(90, 30));
29+
}
30+
31+
public function testModifyOddSize(): void
32+
{
33+
$image = $this->createTestImage(375, 250);
34+
$image->modify(new CoverDownModifier(240, 90, 'center'));
35+
$this->assertEquals(240, $image->width());
36+
$this->assertEquals(90, $image->height());
37+
}
38+
}

tests/Unit/Drivers/Gd/Modifiers/CoverModifierTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,12 @@ public function testModify(): void
2727
$this->assertColor(0, 0, 255, 255, $image->pickColor(70, 52));
2828
$this->assertTransparency($image->pickColor(90, 30));
2929
}
30+
31+
public function testModifyOddSize(): void
32+
{
33+
$image = $this->createTestImage(375, 250);
34+
$image->modify(new CoverModifier(240, 90, 'center'));
35+
$this->assertEquals(240, $image->width());
36+
$this->assertEquals(90, $image->height());
37+
}
3038
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers;
6+
7+
use PHPUnit\Framework\Attributes\CoversClass;
8+
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
9+
use Intervention\Image\Modifiers\CoverDownModifier;
10+
use Intervention\Image\Tests\ImagickTestCase;
11+
12+
#[RequiresPhpExtension('imagick')]
13+
#[CoversClass(\Intervention\Image\Modifiers\CoverModifier::class)]
14+
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\CoverModifier::class)]
15+
final class CoverDownModifierTest extends ImagickTestCase
16+
{
17+
public function testModify(): void
18+
{
19+
$image = $this->readTestImage('blocks.png');
20+
$this->assertEquals(640, $image->width());
21+
$this->assertEquals(480, $image->height());
22+
$image->modify(new CoverDownModifier(100, 100, 'center'));
23+
$this->assertEquals(100, $image->width());
24+
$this->assertEquals(100, $image->height());
25+
$this->assertColor(255, 0, 0, 255, $image->pickColor(90, 90));
26+
$this->assertColor(0, 255, 0, 255, $image->pickColor(65, 70));
27+
$this->assertColor(0, 0, 255, 255, $image->pickColor(70, 52));
28+
$this->assertTransparency($image->pickColor(90, 30));
29+
}
30+
31+
public function testModifyOddSize(): void
32+
{
33+
$image = $this->createTestImage(375, 250);
34+
$image->modify(new CoverDownModifier(240, 90, 'center'));
35+
$this->assertEquals(240, $image->width());
36+
$this->assertEquals(90, $image->height());
37+
}
38+
}

tests/Unit/Drivers/Imagick/Modifiers/CoverModifierTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,12 @@ public function testModify(): void
2727
$this->assertColor(0, 0, 255, 255, $image->pickColor(70, 52));
2828
$this->assertTransparency($image->pickColor(90, 30));
2929
}
30+
31+
public function testModifyOddSize(): void
32+
{
33+
$image = $this->createTestImage(375, 250);
34+
$image->modify(new CoverModifier(240, 90, 'center'));
35+
$this->assertEquals(240, $image->width());
36+
$this->assertEquals(90, $image->height());
37+
}
3038
}

0 commit comments

Comments
 (0)