Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in cover modifiers #1361

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Drivers/AbstractDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function specialize(
/**
* {@inheritdoc}
*
* @throws NotSupportedException
* @see DriverInterface::specializeMultiple()
*/
public function specializeMultiple(array $objects): array
Expand Down
1 change: 1 addition & 0 deletions src/Drivers/Gd/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function createImage(int $width, int $height): ImageInterface
/**
* {@inheritdoc}
*
* @throws RuntimeException
* @see DriverInterface::createAnimation()
*/
public function createAnimation(callable $init): ImageInterface
Expand Down
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);
}
}
1 change: 1 addition & 0 deletions src/Drivers/Imagick/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function createImage(int $width, int $height): ImageInterface
/**
* {@inheritdoc}
*
* @throws RuntimeException
* @see DriverInterface::createAnimation()
*/
public function createAnimation(callable $init): ImageInterface
Expand Down
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());
}
}