diff --git a/src/Drivers/Gd/Modifiers/TextModifier.php b/src/Drivers/Gd/Modifiers/TextModifier.php index 9d51e6aa..a01db204 100644 --- a/src/Drivers/Gd/Modifiers/TextModifier.php +++ b/src/Drivers/Gd/Modifiers/TextModifier.php @@ -12,7 +12,7 @@ class TextModifier extends DriverModifier public function apply(ImageInterface $image): ImageInterface { $processor = $this->fontProcessor(); - $lines = $processor->getAlignedTextBlock($this->position, $this->text); + $lines = $processor->alignedTextBlock($this->position, $this->text); $color = $this->driver()->colorToNative( $this->driver()->handleInput($this->font->color()), @@ -38,8 +38,8 @@ class TextModifier extends DriverModifier imagestring( $frame->native(), $processor->getGdFont(), - $line->getPosition()->x(), - $line->getPosition()->y(), + $line->position()->x(), + $line->position()->y(), $line, $color ); diff --git a/src/Drivers/Imagick/Modifiers/TextModifier.php b/src/Drivers/Imagick/Modifiers/TextModifier.php index 8f7dfa7d..24bbf9d3 100644 --- a/src/Drivers/Imagick/Modifiers/TextModifier.php +++ b/src/Drivers/Imagick/Modifiers/TextModifier.php @@ -11,7 +11,7 @@ class TextModifier extends DriverModifier public function apply(ImageInterface $image): ImageInterface { $processor = $this->fontProcessor(); - $lines = $processor->getAlignedTextBlock($this->position, $this->text); + $lines = $processor->alignedTextBlock($this->position, $this->text); $color = $this->driver()->colorToNative( $this->driver()->handleInput($this->font->color()), diff --git a/src/Image.php b/src/Image.php index 65057008..3609468f 100644 --- a/src/Image.php +++ b/src/Image.php @@ -3,6 +3,7 @@ namespace Intervention\Image; use Countable; +use Traversable; use Intervention\Image\Analyzers\ColorspaceAnalyzer; use Intervention\Image\Analyzers\HeightAnalyzer; use Intervention\Image\Analyzers\PixelColorAnalyzer; @@ -11,7 +12,6 @@ use Intervention\Image\Analyzers\ProfileAnalyzer; use Intervention\Image\Analyzers\ResolutionAnalyzer; use Intervention\Image\Analyzers\WidthAnalyzer; use Intervention\Image\Geometry\Point; -use Traversable; use Intervention\Image\Geometry\Rectangle; use Intervention\Image\Interfaces\AnalyzerInterface; use Intervention\Image\Interfaces\CollectionInterface; diff --git a/tests/Drivers/Gd/ImageTest.php b/tests/Drivers/Gd/ImageTest.php index db2c70b7..d913a3df 100644 --- a/tests/Drivers/Gd/ImageTest.php +++ b/tests/Drivers/Gd/ImageTest.php @@ -2,161 +2,140 @@ namespace Intervention\Image\Tests\Drivers\Gd; +use Intervention\Image\Analyzers\WidthAnalyzer; use Intervention\Image\Collection; +use Intervention\Image\Drivers\Gd\Core; +use Intervention\Image\Drivers\Gd\Driver; use Intervention\Image\Drivers\Gd\Frame; -use Intervention\Image\Drivers\Gd\Image; -use Intervention\Image\Geometry\Rectangle; +use Intervention\Image\EncodedImage; +use Intervention\Image\Encoders\PngEncoder; +use Intervention\Image\Exceptions\MissingDriverComponentException; +use Intervention\Image\Image; +use Intervention\Image\Interfaces\ColorInterface; +use Intervention\Image\Interfaces\ColorspaceInterface; +use Intervention\Image\Interfaces\ResolutionInterface; +use Intervention\Image\Interfaces\SizeInterface; +use Intervention\Image\Modifiers\GreyscaleModifier; use Intervention\Image\Tests\TestCase; -use Intervention\Image\Colors\Rgb\Color; -use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace; -use Intervention\Image\Colors\Cmyk\Colorspace as CmykColorspace; -use Intervention\Image\Exceptions\NotSupportedException; -use Intervention\Image\Exceptions\AnimationException; -use Intervention\Image\Resolution; +use Intervention\Image\Typography\Font; -/** - * @requires extension gd - * @covers \Intervention\Image\Drivers\Gd\Image - */ -// class ImageTest extends TestCase -// { -// protected Image $image; -// -// protected function setUp(): void -// { -// $gd1 = imagecreatetruecolor(3, 2); -// imagefill($gd1, 0, 0, imagecolorallocate($gd1, 255, 0, 0)); -// $gd2 = imagecreatetruecolor(3, 2); -// imagefill($gd2, 0, 0, imagecolorallocate($gd1, 0, 255, 0)); -// $gd3 = imagecreatetruecolor(3, 2); -// imagefill($gd3, 0, 0, imagecolorallocate($gd1, 0, 0, 255)); -// $this->image = new Image(new Collection([ -// new Frame($gd1), -// new Frame($gd2), -// new Frame($gd3), -// ])); -// } -// -// public function testConstructor(): void -// { -// $this->assertInstanceOf(Image::class, $this->image); -// } -// -// public function testCount(): void -// { -// $this->assertEquals(3, $this->image->count()); -// $this->assertEquals(3, count($this->image)); -// } -// -// public function testIterator(): void -// { -// foreach ($this->image as $frame) { -// $this->assertInstanceOf(Frame::class, $frame); -// } -// } -// -// public function testGetFrame(): void -// { -// $this->assertInstanceOf(Frame::class, $this->image->frame()); -// $this->assertInstanceOf(Frame::class, $this->image->frame(1)); -// } -// -// public function testAddFrame(): void -// { -// $this->assertCount(3, $this->image); -// $result = $this->image->addFrame(new Frame(imagecreatetruecolor(3, 2))); -// $this->assertInstanceOf(Image::class, $result); -// $this->assertCount(4, $this->image); -// } -// -// public function testSetGetLoops(): void -// { -// $this->assertEquals(0, $this->image->loops()); -// $result = $this->image->setLoops(12); -// $this->assertEquals(12, $this->image->loops()); -// $this->assertInstanceOf(Image::class, $result); -// } -// -// public function testIsAnimated(): void -// { -// $this->assertTrue($this->image->isAnimated()); -// } -// -// public function testWidth(): void -// { -// $this->assertEquals(3, $this->image->width()); -// } -// -// public function testHeight(): void -// { -// $this->assertEquals(2, $this->image->height()); -// } -// -// public function testGetSize(): void -// { -// $this->assertInstanceOf(Rectangle::class, $this->image->size()); -// } -// -// public function testPickColor(): void -// { -// $color = $this->image->pickColor(0, 0); -// $this->assertInstanceOf(Color::class, $color); -// $this->assertEquals([255, 0, 0, 255], $color->toArray()); -// -// $color = $this->image->pickColor(0, 0, 1); -// $this->assertInstanceOf(Color::class, $color); -// $this->assertEquals([0, 255, 0, 255], $color->toArray()); -// -// $color = $this->image->pickColor(0, 0, 2); -// $this->assertInstanceOf(Color::class, $color); -// $this->assertEquals([0, 0, 255, 255], $color->toArray()); -// -// $this->expectException(AnimationException::class); -// $this->image->pickColor(0, 0, 3); -// } -// -// public function testPickColors(): void -// { -// $colors = $this->image->pickColors(0, 0); -// $this->assertInstanceOf(Collection::class, $colors); -// $this->assertCount(3, $colors); -// $this->assertEquals([255, 0, 0, 255], $colors->get(0)->toArray()); -// $this->assertEquals([0, 255, 0, 255], $colors->get(1)->toArray()); -// $this->assertEquals([0, 0, 255, 255], $colors->get(2)->toArray()); -// } -// -// public function testGetColorspace(): void -// { -// $this->assertInstanceOf(RgbColorspace::class, $this->image->colorspace()); -// } -// -// public function testSetColorspace(): void -// { -// $result = $this->image->setColorspace('rgb'); -// $this->assertInstanceOf(Image::class, $result); -// $this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); -// -// $result = $this->image->setColorspace(RgbColorspace::class); -// $this->assertInstanceOf(Image::class, $result); -// $this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); -// -// $result = $this->image->setColorspace(new RgbColorspace()); -// $this->assertInstanceOf(Image::class, $result); -// $this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); -// -// $this->expectException(NotSupportedException::class); -// $this->image->setColorspace('cmyk'); -// -// $this->expectException(NotSupportedException::class); -// $this->image->setColorspace(CmykColorspace::class); -// -// $this->expectException(NotSupportedException::class); -// $this->image->setColorspace(new CmykColorspace()); -// } -// -// public function testResolution(): void -// { -// $result = $this->image->resolution(); -// $this->assertInstanceOf(Resolution::class, $result); -// } -// } +class ImageTest extends TestCase +{ + protected Image $image; + + public function setUp(): void + { + $this->image = new Image( + new Driver(), + new Core([ + new Frame(imagecreatetruecolor(3, 2)), + new Frame(imagecreatetruecolor(3, 2)), + ]), + new Collection([ + 'test' => 'foo' + ]), + ); + } + + public function testDriver(): void + { + $this->assertInstanceOf(Driver::class, $this->image->driver()); + } + + public function testCore(): void + { + $this->assertInstanceOf(Core::class, $this->image->core()); + } + + public function testCount(): void + { + $this->assertEquals(2, $this->image->count()); + } + + public function testIteration(): void + { + foreach ($this->image as $frame) { + $this->assertInstanceOf(Frame::class, $frame); + } + } + + public function testIsAnimated(): void + { + $this->assertTrue($this->image->isAnimated()); + } + + public function testLoops(): void + { + $this->assertEquals(0, $this->image->loops()); + } + + public function testExif(): void + { + $this->assertInstanceOf(Collection::class, $this->image->exif()); + $this->assertEquals('foo', $this->image->exif('test')); + } + + public function testModify(): void + { + $result = $this->image->modify(new GreyscaleModifier()); + $this->assertInstanceOf(Image::class, $result); + } + + public function testAnalyze(): void + { + $result = $this->image->analyze(new WidthAnalyzer()); + $this->assertEquals(3, $result); + } + + public function testEncode(): void + { + $result = $this->image->encode(new PngEncoder()); + $this->assertInstanceOf(EncodedImage::class, $result); + } + + public function testWidthHeightSize(): void + { + $this->assertEquals(3, $this->image->width()); + $this->assertEquals(2, $this->image->height()); + $this->assertInstanceOf(SizeInterface::class, $this->image->size()); + } + + public function testColorspace(): void + { + $this->assertInstanceOf(ColorspaceInterface::class, $this->image->colorspace()); + } + + public function testResolution(): void + { + $this->assertInstanceOf(ResolutionInterface::class, $this->image->resolution()); + } + + public function testPickColor(): void + { + $this->assertInstanceOf(ColorInterface::class, $this->image->pickColor(0, 0)); + $this->assertInstanceOf(ColorInterface::class, $this->image->pickColor(0, 0, 1)); + } + + public function testPickColors(): void + { + $result = $this->image->pickColors(0, 0); + $this->assertInstanceOf(Collection::class, $result); + $this->assertEquals(2, $result->count()); + } + + public function testProfile(): void + { + $this->expectException(MissingDriverComponentException::class); + $this->image->profile(); + } + + public function testSharpen(): void + { + $this->assertInstanceOf(Image::class, $this->image->sharpen(12)); + } + + public function testText(): void + { + $this->assertInstanceOf(Image::class, $this->image->text('test', 0, 0, new Font())); + } +} diff --git a/tests/Drivers/Imagick/ImageTest.php b/tests/Drivers/Imagick/ImageTest.php index 4adeb0dd..ebf4b696 100644 --- a/tests/Drivers/Imagick/ImageTest.php +++ b/tests/Drivers/Imagick/ImageTest.php @@ -3,163 +3,135 @@ namespace Intervention\Image\Tests\Drivers\Imagick; use Imagick; -use ImagickPixel; -use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace; -use Intervention\Image\Colors\Cmyk\Colorspace as CmykColorspace; -use Intervention\Image\Colors\Profile; +use Intervention\Image\Analyzers\WidthAnalyzer; +use Intervention\Image\Collection; +use Intervention\Image\Drivers\Imagick\Core; +use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Drivers\Imagick\Frame; -use Intervention\Image\Drivers\Imagick\Image; -use Intervention\Image\Exceptions\AnimationException; +use Intervention\Image\EncodedImage; +use Intervention\Image\Encoders\PngEncoder; use Intervention\Image\Exceptions\ColorException; -use Intervention\Image\Geometry\Rectangle; -use Intervention\Image\Resolution; +use Intervention\Image\Exceptions\MissingDriverComponentException; +use Intervention\Image\Image; +use Intervention\Image\Interfaces\ColorInterface; +use Intervention\Image\Interfaces\ColorspaceInterface; +use Intervention\Image\Interfaces\ResolutionInterface; +use Intervention\Image\Interfaces\SizeInterface; +use Intervention\Image\Modifiers\GreyscaleModifier; use Intervention\Image\Tests\TestCase; +use Intervention\Image\Typography\Font; -/** - * @requires extension imagick - * @covers \Intervention\Image\Drivers\Imagick\Image - */ -// class ImageTest extends TestCase -// { -// protected Image $image; -// -// protected function setUp(): void -// { -// // create base image -// $imagick = new Imagick(); -// -// // add frame -// $frame = new Imagick(); -// $frame->newImage(3, 2, new ImagickPixel('red'), 'png'); -// $imagick->addImage($frame); -// -// // add frame -// $frame = new Imagick(); -// $frame->newImage(3, 2, new ImagickPixel('green'), 'png'); -// $imagick->addImage($frame); -// -// // create intervention image -// $this->image = new Image($imagick); -// } -// -// public function testConstructor(): void -// { -// $this->assertInstanceOf(Image::class, $this->image); -// } -// -// public function testGetFrame(): void -// { -// $this->assertInstanceOf(Frame::class, $this->image->frame()); -// $this->assertInstanceOf(Frame::class, $this->image->frame(1)); -// $this->expectException(AnimationException::class); -// $this->image->frame(2); -// } -// -// public function testAddFrame(): void -// { -// $frame = new Imagick(); -// $frame->newImage(3, 2, new ImagickPixel('blue'), 'png'); -// $frame = new Frame($frame); -// -// $this->assertCount(2, $this->image); -// $result = $this->image->addFrame($frame); -// $this->assertInstanceOf(Image::class, $result); -// $this->assertCount(3, $this->image); -// } -// -// public function testIterator(): void -// { -// foreach ($this->image as $frame) { -// $this->assertInstanceOf(Frame::class, $frame); -// } -// } -// -// public function testCount(): void -// { -// $this->assertEquals(2, $this->image->count()); -// $this->assertEquals(2, count($this->image)); -// } -// -// public function testWidth(): void -// { -// $this->assertEquals(3, $this->image->width()); -// } -// -// public function testHeight(): void -// { -// $this->assertEquals(2, $this->image->height()); -// } -// -// public function testGetSize(): void -// { -// $this->assertInstanceOf(Rectangle::class, $this->image->size()); -// } -// -// public function testGetColorspace(): void -// { -// $imagick = new Imagick(); -// $imagick->readImageBlob($this->getTestImageData('test.jpg')); -// $image = new Image($imagick); -// $this->assertInstanceOf(RgbColorspace::class, $image->colorspace()); -// -// $imagick = new Imagick(); -// $imagick->readImageBlob($this->getTestImageData('cmyk.jpg')); -// $image = new Image($imagick); -// $this->assertInstanceOf(CmykColorspace::class, $image->colorspace()); -// } -// -// public function testSetColorspace(): void -// { -// $result = $this->image->setColorspace('rgb'); -// $this->assertInstanceOf(Image::class, $result); -// $this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); -// -// $result = $this->image->setColorspace(RgbColorspace::class); -// $this->assertInstanceOf(Image::class, $result); -// $this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); -// -// $result = $this->image->setColorspace(new RgbColorspace()); -// $this->assertInstanceOf(Image::class, $result); -// $this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); -// -// $result = $this->image->setColorspace('cmyk'); -// $this->assertInstanceOf(Image::class, $result); -// $this->assertInstanceOf(CmykColorspace::class, $result->colorspace()); -// -// $result = $this->image->setColorspace(CmykColorspace::class); -// $this->assertInstanceOf(Image::class, $result); -// $this->assertInstanceOf(CmykColorspace::class, $result->colorspace()); -// -// $result = $this->image->setColorspace(new CmykColorspace()); -// $this->assertInstanceOf(Image::class, $result); -// $this->assertInstanceOf(CmykColorspace::class, $result->colorspace()); -// } -// -// public function testSetGetProfile(): void -// { -// $imagick = new Imagick(); -// $imagick->readImageBlob($this->getTestImageData('test.jpg')); -// $image = new Image($imagick); -// $result = $image->profile(); -// $this->assertInstanceOf(Profile::class, $result); -// $result = $image->setProfile($result); -// $this->assertInstanceOf(Image::class, $result); -// } -// -// public function testRemoveProfile(): void -// { -// $imagick = new Imagick(); -// $imagick->readImageBlob($this->getTestImageData('test.jpg')); -// $image = new Image($imagick); -// $result = $image->removeProfile(); -// $this->assertInstanceOf(Image::class, $result); -// $this->expectException(ColorException::class); -// $image->profile(); -// } -// -// public function testResolution(): void -// { -// $result = $this->image->resolution(); -// $this->assertInstanceOf(Resolution::class, $result); -// } -// } +class ImageTest extends TestCase +{ + protected Image $image; + + public function setUp(): void + { + $imagick = new Imagick(); + $imagick->readImage(__DIR__ . '/../../images/animation.gif'); + $this->image = new Image( + new Driver(), + new Core($imagick), + new Collection([ + 'test' => 'foo' + ]), + ); + } + + public function testDriver(): void + { + $this->assertInstanceOf(Driver::class, $this->image->driver()); + } + + public function testCore(): void + { + $this->assertInstanceOf(Core::class, $this->image->core()); + } + + public function testCount(): void + { + $this->assertEquals(8, $this->image->count()); + } + + public function testIteration(): void + { + foreach ($this->image as $frame) { + $this->assertInstanceOf(Frame::class, $frame); + } + } + + public function testIsAnimated(): void + { + $this->assertTrue($this->image->isAnimated()); + } + + public function testLoops(): void + { + $this->assertEquals(3, $this->image->loops()); + } + + public function testExif(): void + { + $this->assertInstanceOf(Collection::class, $this->image->exif()); + $this->assertEquals('foo', $this->image->exif('test')); + } + + public function testModify(): void + { + $result = $this->image->modify(new GreyscaleModifier()); + $this->assertInstanceOf(Image::class, $result); + } + + public function testAnalyze(): void + { + $result = $this->image->analyze(new WidthAnalyzer()); + $this->assertEquals(20, $result); + } + + public function testEncode(): void + { + $result = $this->image->encode(new PngEncoder()); + $this->assertInstanceOf(EncodedImage::class, $result); + } + + public function testWidthHeightSize(): void + { + $this->assertEquals(20, $this->image->width()); + $this->assertEquals(15, $this->image->height()); + $this->assertInstanceOf(SizeInterface::class, $this->image->size()); + } + + public function testColorspace(): void + { + $this->assertInstanceOf(ColorspaceInterface::class, $this->image->colorspace()); + } + + public function testResolution(): void + { + $this->assertInstanceOf(ResolutionInterface::class, $this->image->resolution()); + } + + public function testPickColor(): void + { + $this->assertInstanceOf(ColorInterface::class, $this->image->pickColor(0, 0)); + $this->assertInstanceOf(ColorInterface::class, $this->image->pickColor(0, 0, 1)); + } + + public function testPickColors(): void + { + $result = $this->image->pickColors(0, 0); + $this->assertInstanceOf(Collection::class, $result); + $this->assertEquals(8, $result->count()); + } + + public function testProfile(): void + { + $this->expectException(ColorException::class); + $this->image->profile(); + } + + public function testSharpen(): void + { + $this->assertInstanceOf(Image::class, $this->image->sharpen(12)); + } +} diff --git a/tests/ImageTest.php b/tests/ImageTest.php deleted file mode 100644 index 085bbbb3..00000000 --- a/tests/ImageTest.php +++ /dev/null @@ -1,145 +0,0 @@ -shouldReceive('apply')->andReturn( - Mockery::mock(ImageInterface::class) - ); - - $encoder = Mockery::mock(EncoderInterface::class); - $encoder->shouldReceive('encode')->andReturn( - new EncodedImage('foo') - ); - - $analyzer = Mockery::mock(AnalyzerInterface::class); - $analyzer->shouldReceive('analyze')->andReturn( - Mockery::mock(ColorspaceInterface::class) - ); - - $this->encoder_mock = $encoder; - $this->modifier_mock = $modifier; - $this->analyzer_mock = $analyzer; - } - - private function testImage(): Image - { - $core = Mockery::mock(CoreInterface::class); - $core->shouldReceive('width')->andReturn(300); - $core->shouldReceive('height')->andReturn(200); - $core->shouldReceive('count')->andReturn(12); - $core->shouldReceive('loops')->andReturn(12); - $core->shouldReceive('resolve')->andReturn(new GreyscaleModifier()); - - $driver = Mockery::mock(DriverInterface::class); - $driver->shouldReceive('resolve')->with($this->modifier_mock)->andReturn($this->modifier_mock); - $driver->shouldReceive('resolve')->with($this->encoder_mock)->andReturn($this->encoder_mock); - $driver->shouldReceive('resolve')->with($this->analyzer_mock)->andReturn($this->analyzer_mock); - - $exif = Mockery::mock(CollectionInterface::class); - - return new Image($driver, $core, $exif); - } - - public function testConstructor(): void - { - $image = $this->testImage(); - $this->assertInstanceOf(Image::class, $image); - } - - public function testDriver(): void - { - $image = $this->testImage(); - $this->assertInstanceOf(DriverInterface::class, $image->driver()); - } - - public function testCore(): void - { - $image = $this->testImage(); - $this->assertInstanceOf(CoreInterface::class, $image->core()); - } - - public function testWidthHeightSize(): void - { - $image = $this->testImage(); - $this->assertEquals(300, $image->width()); - $this->assertEquals(200, $image->height()); - $this->assertInstanceOf(SizeInterface::class, $image->size()); - $this->assertEquals(300, $image->size()->width()); - $this->assertEquals(200, $image->size()->height()); - } - - public function testCount(): void - { - $image = $this->testImage(); - $this->assertEquals(12, $image->count()); - } - - public function testGetIterator(): void - { - $image = $this->testImage(); - $this->assertInstanceOf(CoreInterface::class, $image->getIterator()); - } - - public function testIsAnimated(): void - { - $image = $this->testImage(); - $this->assertTrue($image->isAnimated()); - } - - public function testLoops(): void - { - $image = $this->testImage(); - $this->assertEquals(12, $image->loops()); - } - - public function testColorspace(): void - { - $image = $this->testImage(); - $this->assertInstanceOf(Colorspace::class, $image->colorspace()); - } - - public function testExif(): void - { - $image = $this->testImage(); - $this->assertInstanceOf(CollectionInterface::class, $image->exif()); - } - - public function testModify(): void - { - $image = $this->testImage(); - $result = $image->modify($this->modifier_mock); - $this->assertInstanceOf(ImageInterface::class, $result); - } - - public function testEncode(): void - { - $image = $this->testImage(); - $result = $image->encode($this->encoder_mock); - $this->assertInstanceOf(EncodedImageInterface::class, $result); - } -}