1
0
mirror of https://github.com/Intervention/image.git synced 2025-01-17 20:28:21 +01:00

Add tests

This commit is contained in:
Oliver Vogel 2023-12-06 18:39:27 +01:00
parent aa59a486d8
commit a3d524fa7f
6 changed files with 85 additions and 0 deletions

View File

@ -15,6 +15,19 @@ class ResizeCanvasModifierTest extends TestCase
use CanCreateGdTestImage; use CanCreateGdTestImage;
public function testModify(): void public function testModify(): void
{
$image = $this->createTestImage(1, 1);
$this->assertEquals(1, $image->width());
$this->assertEquals(1, $image->height());
$image->modify(new ResizeCanvasModifier(3, 3, 'ff0', 'center'));
$this->assertEquals(3, $image->width());
$this->assertEquals(3, $image->height());
$this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0));
$this->assertColor(255, 0, 0, 255, $image->pickColor(1, 1));
$this->assertColor(255, 255, 0, 255, $image->pickColor(2, 2));
}
public function testModifyWithTransparency(): void
{ {
$image = $this->readTestImage('tile.png'); $image = $this->readTestImage('tile.png');
$this->assertEquals(16, $image->width()); $this->assertEquals(16, $image->width());

View File

@ -15,6 +15,19 @@ class ResizeCanvasRelativeModifierTest extends TestCase
use CanCreateGdTestImage; use CanCreateGdTestImage;
public function testModify(): void public function testModify(): void
{
$image = $this->createTestImage(1, 1);
$this->assertEquals(1, $image->width());
$this->assertEquals(1, $image->height());
$image->modify(new ResizeCanvasRelativeModifier(2, 2, 'ff0', 'center'));
$this->assertEquals(3, $image->width());
$this->assertEquals(3, $image->height());
$this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0));
$this->assertColor(255, 0, 0, 255, $image->pickColor(1, 1));
$this->assertColor(255, 255, 0, 255, $image->pickColor(2, 2));
}
public function testModifyWithTransparency(): void
{ {
$image = $this->readTestImage('tile.png'); $image = $this->readTestImage('tile.png');
$this->assertEquals(16, $image->width()); $this->assertEquals(16, $image->width());

View File

@ -15,6 +15,19 @@ class ResizeCanvasModifierTest extends TestCase
use CanCreateImagickTestImage; use CanCreateImagickTestImage;
public function testModify(): void public function testModify(): void
{
$image = $this->createTestImage(1, 1);
$this->assertEquals(1, $image->width());
$this->assertEquals(1, $image->height());
$image->modify(new ResizeCanvasModifier(3, 3, 'ff0', 'center'));
$this->assertEquals(3, $image->width());
$this->assertEquals(3, $image->height());
$this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0));
$this->assertColor(255, 0, 0, 255, $image->pickColor(1, 1));
$this->assertColor(255, 255, 0, 255, $image->pickColor(2, 2));
}
public function testModifyWithTransparency(): void
{ {
$image = $this->readTestImage('tile.png'); $image = $this->readTestImage('tile.png');
$this->assertEquals(16, $image->width()); $this->assertEquals(16, $image->width());

View File

@ -15,6 +15,19 @@ class ResizeCanvasRelativeModifierTest extends TestCase
use CanCreateImagickTestImage; use CanCreateImagickTestImage;
public function testModify(): void public function testModify(): void
{
$image = $this->createTestImage(1, 1);
$this->assertEquals(1, $image->width());
$this->assertEquals(1, $image->height());
$image->modify(new ResizeCanvasRelativeModifier(2, 2, 'ff0', 'center'));
$this->assertEquals(3, $image->width());
$this->assertEquals(3, $image->height());
$this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0));
$this->assertColor(255, 0, 0, 255, $image->pickColor(1, 1));
$this->assertColor(255, 255, 0, 255, $image->pickColor(2, 2));
}
public function testModifyWithTransparency(): void
{ {
$image = $this->readTestImage('tile.png'); $image = $this->readTestImage('tile.png');
$this->assertEquals(16, $image->width()); $this->assertEquals(16, $image->width());

View File

@ -17,6 +17,19 @@ trait CanCreateGdTestImage
); );
} }
public function createTestImage(int $width, int $height): Image
{
$gd = imagecreatetruecolor($width, $height);
imagefill($gd, 0, 0, imagecolorallocate($gd, 255, 0, 0));
return new Image(
new Driver(),
new Core([
new Frame($gd)
])
);
}
public function createTestAnimation(): Image public function createTestAnimation(): Image
{ {
$gd1 = imagecreatetruecolor(3, 2); $gd1 = imagecreatetruecolor(3, 2);

View File

@ -2,7 +2,11 @@
namespace Intervention\Image\Tests\Traits; namespace Intervention\Image\Tests\Traits;
use Imagick;
use ImagickPixel;
use Intervention\Image\Drivers\Imagick\Core;
use Intervention\Image\Drivers\Imagick\Decoders\FilePathImageDecoder; use Intervention\Image\Drivers\Imagick\Decoders\FilePathImageDecoder;
use Intervention\Image\Drivers\Imagick\Driver;
use Intervention\Image\Image; use Intervention\Image\Image;
trait CanCreateImagickTestImage trait CanCreateImagickTestImage
@ -13,4 +17,20 @@ trait CanCreateImagickTestImage
sprintf('%s/../images/%s', __DIR__, $filename) sprintf('%s/../images/%s', __DIR__, $filename)
); );
} }
public function createTestImage(int $width, int $height): Image
{
$background = new ImagickPixel('rgb(255, 0, 0)');
$imagick = new Imagick();
$imagick->newImage($width, $height, $background, 'png');
$imagick->setType(Imagick::IMGTYPE_UNDEFINED);
$imagick->setImageType(Imagick::IMGTYPE_UNDEFINED);
$imagick->setColorspace(Imagick::COLORSPACE_SRGB);
$imagick->setImageResolution(96, 96);
return new Image(
new Driver(),
new Core($imagick)
);
}
} }