1
0
mirror of https://github.com/Intervention/image.git synced 2025-09-03 10:53:01 +02:00

added polygon drawing

This commit is contained in:
Oliver Vogel
2014-07-27 12:44:21 +02:00
parent 837983c825
commit b8cc2431fc
7 changed files with 292 additions and 0 deletions

View File

@@ -1027,6 +1027,14 @@ class GdSystemTest extends PHPUnit_Framework_TestCase
$this->assertEquals('c214f58de03d171f7f278a7b957bab50', $img->checksum());
}
public function testPolygonImage()
{
$img = $this->manager()->canvas(16, 16, 'ffffff');
$points = array(3, 3, 11, 11, 7, 13);
$img->polygon($points, function ($draw) { $draw->background('#ff0000'); $draw->border(1, '#0000ff'); });
$this->assertEquals('e534ff90c8026f9317b99071fda01ed4', $img->checksum());
}
public function testResetImage()
{
$img = $this->manager()->make('tests/images/tile.png');

View File

@@ -1000,6 +1000,14 @@ class ImagickSystemTest extends PHPUnit_Framework_TestCase
$this->assertEquals('a433c7c1a842ef83e1cb45875371358c', $img->checksum());
}
public function testPolygonImage()
{
$img = $this->manager()->canvas(16, 16, 'ffffff');
$points = array(3, 3, 11, 11, 7, 13);
$img->polygon($points, function ($draw) { $draw->background('#ff0000'); $draw->border(1, '#0000ff'); });
$this->assertEquals('e301afe179da858d441ad8fc0eb5490a', $img->checksum());
}
public function testResetImage()
{
$img = $this->manager()->make('tests/images/tile.png');

View File

@@ -0,0 +1,44 @@
<?php
use Intervention\Image\Commands\PolygonCommand;
class PolygonCommandTest extends PHPUnit_Framework_TestCase
{
public function tearDown()
{
Mockery::close();
}
public function testGd()
{
$points = array(1, 2, 3, 4, 5, 6);
$resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
$driver = Mockery::mock('\Intervention\Image\Gd\Driver');
$driver->shouldReceive('getDriverName')->once()->andReturn('Gd');
$image = Mockery::mock('\Intervention\Image\Image');
$image->shouldReceive('getDriver')->once()->andReturn($driver);
$image->shouldReceive('getCore')->once()->andReturn($resource);
$command = new PolygonCommand(array($points));
$result = $command->execute($image);
$this->assertTrue($result);
$this->assertFalse($command->hasOutput());
}
public function testImagick()
{
$points = array(1, 2, 3, 4, 5, 6);
$imagick = Mockery::mock('\Imagick');
$imagick->shouldReceive('drawimage');
$driver = Mockery::mock('\Intervention\Image\Imagick\Driver');
$driver->shouldReceive('getDriverName')->once()->andReturn('Imagick');
$image = Mockery::mock('\Intervention\Image\Image');
$image->shouldReceive('getDriver')->once()->andReturn($driver);
$image->shouldReceive('getCore')->once()->andReturn($imagick);
$command = new PolygonCommand(array($points));
$result = $command->execute($image);
$this->assertTrue($result);
$this->assertFalse($command->hasOutput());
}
}

View File

@@ -0,0 +1,56 @@
<?php
use Intervention\Image\Gd\Shapes\PolygonShape as PolygonGd;
use Intervention\Image\Imagick\Shapes\PolygonShape as PolygonImagick;
class PolygonShapeTest extends PHPUnit_Framework_TestCase
{
public function tearDown()
{
Mockery::close();
}
public function testGdConstructor()
{
$polygon = new PolygonGd(array(1, 2, 3, 4, 5, 6));
$this->assertInstanceOf('Intervention\Image\Gd\Shapes\PolygonShape', $polygon);
$this->assertEquals(array(1, 2, 3, 4, 5, 6), $polygon->points);
}
public function testGdApplyToImage()
{
$core = imagecreatetruecolor(300, 200);
$image = Mockery::mock('\Intervention\Image\Image');
$image->shouldReceive('getCore')->once()->andReturn($core);
$polygon = new PolygonGd(array(1, 2, 3, 4, 5, 6));
$result = $polygon->applyToImage($image);
$this->assertInstanceOf('Intervention\Image\Gd\Shapes\PolygonShape', $polygon);
$this->assertTrue($result);
}
public function testImagickConstructor()
{
$polygon = new PolygonImagick(array(1, 2, 3, 4, 5, 6));
$this->assertInstanceOf('Intervention\Image\Imagick\Shapes\PolygonShape', $polygon);
$this->assertEquals(array(
array('x' => 1, 'y' => 2),
array('x' => 3, 'y' => 4),
array('x' => 5, 'y' => 6)),
$polygon->points);
}
public function testImagickApplyToImage()
{
$core = Mockery::mock('\Imagick');
$core->shouldReceive('drawimage')->once();
$image = Mockery::mock('\Intervention\Image\Image');
$image->shouldReceive('getCore')->once()->andReturn($core);
$polygon = new PolygonImagick(array(1, 2, 3, 4, 5, 6));
$result = $polygon->applyToImage($image);
$this->assertInstanceOf('Intervention\Image\Imagick\Shapes\PolygonShape', $polygon);
$this->assertTrue($result);
}
}