mirror of
https://github.com/Intervention/image.git
synced 2025-08-26 15:24:37 +02:00
Fix bug in PadModifier (#1408)
This commit is contained in:
@@ -4,6 +4,21 @@ declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Drivers\Gd\Modifiers;
|
||||
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Interfaces\SizeInterface;
|
||||
|
||||
class PadModifier extends ContainModifier
|
||||
{
|
||||
public function getCropSize(ImageInterface $image): SizeInterface
|
||||
{
|
||||
return $image->size()
|
||||
->containMax(
|
||||
$this->width,
|
||||
$this->height
|
||||
)
|
||||
->alignPivotTo(
|
||||
$this->getResizeSize($image),
|
||||
$this->position
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,21 @@ declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Drivers\Imagick\Modifiers;
|
||||
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Interfaces\SizeInterface;
|
||||
|
||||
class PadModifier extends ContainModifier
|
||||
{
|
||||
public function getCropSize(ImageInterface $image): SizeInterface
|
||||
{
|
||||
return $image->size()
|
||||
->containMax(
|
||||
$this->width,
|
||||
$this->height
|
||||
)
|
||||
->alignPivotTo(
|
||||
$this->getResizeSize($image),
|
||||
$this->position
|
||||
);
|
||||
}
|
||||
}
|
||||
|
42
tests/Unit/Drivers/Gd/Modifiers/PadModifierTest.php
Normal file
42
tests/Unit/Drivers/Gd/Modifiers/PadModifierTest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Intervention\Image\Modifiers\PadModifier;
|
||||
use Intervention\Image\Tests\GdTestCase;
|
||||
|
||||
#[RequiresPhpExtension('gd')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\PadModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\PadModifier::class)]
|
||||
final class PadModifierTest extends GdTestCase
|
||||
{
|
||||
public function testModify(): void
|
||||
{
|
||||
$image = $this->readTestImage('blue.gif');
|
||||
$this->assertEquals(16, $image->width());
|
||||
$this->assertEquals(16, $image->height());
|
||||
$image->modify(new PadModifier(30, 20, 'f00'));
|
||||
$this->assertEquals(30, $image->width());
|
||||
$this->assertEquals(20, $image->height());
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(0, 0));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(0, 19));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(29, 0));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(29, 19));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(6, 2));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(7, 1));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(6, 17));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(7, 18));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(23, 1));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(23, 2));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(23, 17));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(23, 18));
|
||||
$this->assertColor(100, 100, 255, 255, $image->pickColor(7, 2));
|
||||
$this->assertColor(100, 100, 255, 255, $image->pickColor(22, 2));
|
||||
$this->assertColor(100, 100, 255, 255, $image->pickColor(7, 17));
|
||||
$this->assertColor(100, 100, 255, 255, $image->pickColor(22, 17));
|
||||
}
|
||||
}
|
42
tests/Unit/Drivers/Imagick/Modifiers/PadModifierTest.php
Normal file
42
tests/Unit/Drivers/Imagick/Modifiers/PadModifierTest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?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\PadModifier;
|
||||
use Intervention\Image\Tests\ImagickTestCase;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\PadModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\PadModifier::class)]
|
||||
final class PadModifierTest extends ImagickTestCase
|
||||
{
|
||||
public function testModify(): void
|
||||
{
|
||||
$image = $this->readTestImage('blue.gif');
|
||||
$this->assertEquals(16, $image->width());
|
||||
$this->assertEquals(16, $image->height());
|
||||
$image->modify(new PadModifier(30, 20, 'f00'));
|
||||
$this->assertEquals(30, $image->width());
|
||||
$this->assertEquals(20, $image->height());
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(0, 0));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(0, 19));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(29, 0));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(29, 19));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(6, 2));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(7, 1));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(6, 17));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(7, 18));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(23, 1));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(23, 2));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(23, 17));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(23, 18));
|
||||
$this->assertColor(100, 100, 255, 255, $image->pickColor(7, 2));
|
||||
$this->assertColor(100, 100, 255, 255, $image->pickColor(22, 2));
|
||||
$this->assertColor(100, 100, 255, 255, $image->pickColor(7, 17));
|
||||
$this->assertColor(100, 100, 255, 255, $image->pickColor(22, 17));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user