Skip to content

Commit

Permalink
Fix bug in cover modifiers
Browse files Browse the repository at this point in the history
See: #1359
  • Loading branch information
olivervogel committed Jun 6, 2024
1 parent 193324e commit a566769
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Drivers/Gd/Modifiers/CoverDownModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class CoverDownModifier extends CoverModifier
*/
public function getResizeSize(SizeInterface $size): SizeInterface
{
return $size->scaleDown($this->width, $this->height);
return $size->resizeDown($this->width, $this->height);
}
}
2 changes: 1 addition & 1 deletion src/Drivers/Imagick/Modifiers/CoverDownModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class CoverDownModifier extends CoverModifier
*/
public function getResizeSize(SizeInterface $size): SizeInterface
{
return $size->scaleDown($this->width, $this->height);
return $size->resizeDown($this->width, $this->height);
}
}
2 changes: 1 addition & 1 deletion src/Modifiers/CoverModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public function getCropSize(ImageInterface $image): SizeInterface
*/
public function getResizeSize(SizeInterface $size): SizeInterface
{
return $size->scale($this->width, $this->height);
return $size->resize($this->width, $this->height);
}
}
38 changes: 38 additions & 0 deletions tests/Unit/Drivers/Gd/Modifiers/CoverDownModifierTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers;

use Intervention\Image\Drivers\Gd\Modifiers\CoverDownModifier;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Tests\GdTestCase;

#[RequiresPhpExtension('gd')]
#[CoversClass(\Intervention\Image\Modifiers\CoverModifier::class)]
#[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\CoverModifier::class)]
final class CoverDownModifierTest extends GdTestCase
{
public function testModify(): void
{
$image = $this->readTestImage('blocks.png');
$this->assertEquals(640, $image->width());
$this->assertEquals(480, $image->height());
$image->modify(new CoverDownModifier(100, 100, 'center'));
$this->assertEquals(100, $image->width());
$this->assertEquals(100, $image->height());
$this->assertColor(255, 0, 0, 255, $image->pickColor(90, 90));
$this->assertColor(0, 255, 0, 255, $image->pickColor(65, 70));
$this->assertColor(0, 0, 255, 255, $image->pickColor(70, 52));
$this->assertTransparency($image->pickColor(90, 30));
}

public function testModifyOddSize(): void
{
$image = $this->createTestImage(375, 250);
$image->modify(new CoverDownModifier(240, 90, 'center'));
$this->assertEquals(240, $image->width());
$this->assertEquals(90, $image->height());
}
}
8 changes: 8 additions & 0 deletions tests/Unit/Drivers/Gd/Modifiers/CoverModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ public function testModify(): void
$this->assertColor(0, 0, 255, 255, $image->pickColor(70, 52));
$this->assertTransparency($image->pickColor(90, 30));
}

public function testModifyOddSize(): void
{
$image = $this->createTestImage(375, 250);
$image->modify(new CoverModifier(240, 90, 'center'));
$this->assertEquals(240, $image->width());
$this->assertEquals(90, $image->height());
}
}
38 changes: 38 additions & 0 deletions tests/Unit/Drivers/Imagick/Modifiers/CoverDownModifierTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Modifiers\CoverDownModifier;
use Intervention\Image\Tests\ImagickTestCase;

#[RequiresPhpExtension('imagick')]
#[CoversClass(\Intervention\Image\Modifiers\CoverModifier::class)]
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\CoverModifier::class)]
final class CoverDownModifierTest extends ImagickTestCase
{
public function testModify(): void
{
$image = $this->readTestImage('blocks.png');
$this->assertEquals(640, $image->width());
$this->assertEquals(480, $image->height());
$image->modify(new CoverDownModifier(100, 100, 'center'));
$this->assertEquals(100, $image->width());
$this->assertEquals(100, $image->height());
$this->assertColor(255, 0, 0, 255, $image->pickColor(90, 90));
$this->assertColor(0, 255, 0, 255, $image->pickColor(65, 70));
$this->assertColor(0, 0, 255, 255, $image->pickColor(70, 52));
$this->assertTransparency($image->pickColor(90, 30));
}

public function testModifyOddSize(): void
{
$image = $this->createTestImage(375, 250);
$image->modify(new CoverDownModifier(240, 90, 'center'));
$this->assertEquals(240, $image->width());
$this->assertEquals(90, $image->height());
}
}
8 changes: 8 additions & 0 deletions tests/Unit/Drivers/Imagick/Modifiers/CoverModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ public function testModify(): void
$this->assertColor(0, 0, 255, 255, $image->pickColor(70, 52));
$this->assertTransparency($image->pickColor(90, 30));
}

public function testModifyOddSize(): void
{
$image = $this->createTestImage(375, 250);
$image->modify(new CoverModifier(240, 90, 'center'));
$this->assertEquals(240, $image->width());
$this->assertEquals(90, $image->height());
}
}

0 comments on commit a566769

Please sign in to comment.