Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Dec 6, 2023
1 parent aa59a48 commit a3d524f
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/Drivers/Gd/Modifiers/ResizeCanvasModifierTest.php
Expand Up @@ -15,6 +15,19 @@ class ResizeCanvasModifierTest extends TestCase
use CanCreateGdTestImage;

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');
$this->assertEquals(16, $image->width());
Expand Down
13 changes: 13 additions & 0 deletions tests/Drivers/Gd/Modifiers/ResizeCanvasRelativeModifierTest.php
Expand Up @@ -15,6 +15,19 @@ class ResizeCanvasRelativeModifierTest extends TestCase
use CanCreateGdTestImage;

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');
$this->assertEquals(16, $image->width());
Expand Down
13 changes: 13 additions & 0 deletions tests/Drivers/Imagick/Modifiers/ResizeCanvasModifierTest.php
Expand Up @@ -15,6 +15,19 @@ class ResizeCanvasModifierTest extends TestCase
use CanCreateImagickTestImage;

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');
$this->assertEquals(16, $image->width());
Expand Down
Expand Up @@ -15,6 +15,19 @@ class ResizeCanvasRelativeModifierTest extends TestCase
use CanCreateImagickTestImage;

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');
$this->assertEquals(16, $image->width());
Expand Down
13 changes: 13 additions & 0 deletions tests/Traits/CanCreateGdTestImage.php
Expand Up @@ -17,6 +17,19 @@ public function readTestImage($filename = 'test.jpg'): Image
);
}

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
{
$gd1 = imagecreatetruecolor(3, 2);
Expand Down
20 changes: 20 additions & 0 deletions tests/Traits/CanCreateImagickTestImage.php
Expand Up @@ -2,7 +2,11 @@

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\Driver;
use Intervention\Image\Image;

trait CanCreateImagickTestImage
Expand All @@ -13,4 +17,20 @@ public function readTestImage($filename = 'test.jpg'): Image
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)
);
}
}

0 comments on commit a3d524f

Please sign in to comment.