Skip to content

Commit

Permalink
Merge pull request #1361 from Intervention/hotfix/cover-modifier-size
Browse files Browse the repository at this point in the history
Fix bug in cover modifiers
  • Loading branch information
olivervogel authored Jun 6, 2024
2 parents 193324e + 1efc04e commit d428433
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 3 deletions.
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());
}
}

0 comments on commit d428433

Please sign in to comment.