mirror of
https://github.com/Intervention/image.git
synced 2025-09-02 10:23:29 +02:00
PHPUnit 10 Migration (#1302)
* Bump PHPUnit dependencies * Set return type of base TestCase methods From the [PHPUnit 8 release notes][1], the `TestCase` methods below now declare a `void` return type: - `setUpBeforeClass()` - `setUp()` - `assertPreConditions()` - `assertPostConditions()` - `tearDown()` - `tearDownAfterClass()` - `onNotSuccessfulTest()` [1]: https://phpunit.de/announcements/phpunit-8.html * Ignore PHPUnit cache folder * Adopt PHP attributes in test classes * Declare data providers as `static` * Add return types to test methods * Define test classes as `final` * Migrate phpunit.xml to phpunit 10 * Correct phpunit attribute class name * Rename base test class * Restructure test folders * Fix test image paths * Only set rules for php files in .editorconfig * Remove php unit flag in local test env --------- Co-authored-by: Shift <shift@laravelshift.com>
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Analyzers;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Intervention\Image\Analyzers\ColorspaceAnalyzer;
|
||||
use Intervention\Image\Interfaces\ColorspaceInterface;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Analyzers\ColorspaceAnalyzer::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Analyzers\ColorspaceAnalyzer::class)]
|
||||
final class ColorspaceAnalyzerTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testAnalyze(): void
|
||||
{
|
||||
$image = $this->readTestImage('tile.png');
|
||||
$analyzer = new ColorspaceAnalyzer();
|
||||
$result = $analyzer->analyze($image);
|
||||
$this->assertInstanceOf(ColorspaceInterface::class, $result);
|
||||
}
|
||||
}
|
27
tests/Unit/Drivers/Imagick/Analyzers/HeightAnalyzerTest.php
Normal file
27
tests/Unit/Drivers/Imagick/Analyzers/HeightAnalyzerTest.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Analyzers;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Intervention\Image\Analyzers\HeightAnalyzer;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Analyzers\HeightAnalyzer::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Analyzers\HeightAnalyzer::class)]
|
||||
final class HeightAnalyzerTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testAnalyze(): void
|
||||
{
|
||||
$image = $this->readTestImage('tile.png');
|
||||
$analyzer = new HeightAnalyzer();
|
||||
$result = $analyzer->analyze($image);
|
||||
$this->assertEquals(16, $result);
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Analyzers;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Intervention\Image\Analyzers\PixelColorAnalyzer;
|
||||
use Intervention\Image\Interfaces\ColorInterface;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Analyzers\PixelColorAnalyzer::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Analyzers\PixelColorAnalyzer::class)]
|
||||
final class PixelColorAnalyzerTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testAnalyze(): void
|
||||
{
|
||||
$image = $this->readTestImage('tile.png');
|
||||
$analyzer = new PixelColorAnalyzer(0, 0);
|
||||
$result = $analyzer->analyze($image);
|
||||
$this->assertInstanceOf(ColorInterface::class, $result);
|
||||
$this->assertEquals('b4e000', $result->toHex());
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Analyzers;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Intervention\Image\Analyzers\PixelColorsAnalyzer;
|
||||
use Intervention\Image\Collection;
|
||||
use Intervention\Image\Interfaces\ColorInterface;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Analyzers\PixelColorsAnalyzer::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Analyzers\PixelColorsAnalyzer::class)]
|
||||
final class PixelColorsAnalyzerTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testAnalyze(): void
|
||||
{
|
||||
$image = $this->readTestImage('tile.png');
|
||||
$analyzer = new PixelColorsAnalyzer(0, 0);
|
||||
$result = $analyzer->analyze($image);
|
||||
$this->assertInstanceOf(Collection::class, $result);
|
||||
$this->assertInstanceOf(ColorInterface::class, $result->first());
|
||||
$this->assertEquals('b4e000', $result->first()->toHex());
|
||||
}
|
||||
}
|
28
tests/Unit/Drivers/Imagick/Analyzers/ProfileAnalyzerTest.php
Normal file
28
tests/Unit/Drivers/Imagick/Analyzers/ProfileAnalyzerTest.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Analyzers;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Intervention\Image\Analyzers\ProfileAnalyzer;
|
||||
use Intervention\Image\Exceptions\ColorException;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Analyzers\ProfileAnalyzer::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Analyzers\ProfileAnalyzer::class)]
|
||||
final class ProfileAnalyzerTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testAnalyze(): void
|
||||
{
|
||||
$image = $this->readTestImage('tile.png');
|
||||
$analyzer = new ProfileAnalyzer();
|
||||
$this->expectException(ColorException::class);
|
||||
$analyzer->analyze($image);
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Analyzers;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Intervention\Image\Analyzers\ResolutionAnalyzer;
|
||||
use Intervention\Image\Resolution;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Analyzers\ResolutionAnalyzer::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Analyzers\ResolutionAnalyzer::class)]
|
||||
final class ResolutionAnalyzerTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testAnalyze(): void
|
||||
{
|
||||
$image = $this->readTestImage('tile.png');
|
||||
$analyzer = new ResolutionAnalyzer();
|
||||
$result = $analyzer->analyze($image);
|
||||
$this->assertInstanceOf(Resolution::class, $result);
|
||||
}
|
||||
}
|
27
tests/Unit/Drivers/Imagick/Analyzers/WidthAnalyzerTest.php
Normal file
27
tests/Unit/Drivers/Imagick/Analyzers/WidthAnalyzerTest.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Analyzers;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Intervention\Image\Analyzers\WidthAnalyzer;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Analyzers\WidthAnalyzer::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Analyzers\WidthAnalyzer::class)]
|
||||
final class WidthAnalyzerTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testAnalyze(): void
|
||||
{
|
||||
$image = $this->readTestImage('tile.png');
|
||||
$analyzer = new WidthAnalyzer();
|
||||
$result = $analyzer->analyze($image);
|
||||
$this->assertEquals(16, $result);
|
||||
}
|
||||
}
|
27
tests/Unit/Drivers/Imagick/ColorProcessorTest.php
Normal file
27
tests/Unit/Drivers/Imagick/ColorProcessorTest.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick;
|
||||
|
||||
use ImagickPixel;
|
||||
use Intervention\Image\Colors\Rgb\Color;
|
||||
use Intervention\Image\Colors\Rgb\Colorspace;
|
||||
use Intervention\Image\Drivers\Imagick\ColorProcessor;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
|
||||
final class ColorProcessorTest extends BaseTestCase
|
||||
{
|
||||
public function testColorToNative(): void
|
||||
{
|
||||
$processor = new ColorProcessor(new Colorspace());
|
||||
$result = $processor->colorToNative(new Color(255, 55, 0, 255));
|
||||
$this->assertInstanceOf(ImagickPixel::class, $result);
|
||||
}
|
||||
|
||||
public function testNativeToColor(): void
|
||||
{
|
||||
$processor = new ColorProcessor(new Colorspace());
|
||||
$processor->nativeToColor(new ImagickPixel('rgb(255, 55, 0)'));
|
||||
}
|
||||
}
|
146
tests/Unit/Drivers/Imagick/CoreTest.php
Normal file
146
tests/Unit/Drivers/Imagick/CoreTest.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick;
|
||||
|
||||
use Imagick;
|
||||
use ImagickPixel;
|
||||
use Intervention\Image\Drivers\Imagick\Core;
|
||||
use Intervention\Image\Drivers\Imagick\Frame;
|
||||
use Intervention\Image\Exceptions\AnimationException;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
|
||||
final class CoreTest extends BaseTestCase
|
||||
{
|
||||
protected Core $core;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$imagick = new Imagick();
|
||||
|
||||
$im = new Imagick();
|
||||
$im->newImage(10, 10, new ImagickPixel('red'));
|
||||
$imagick->addImage($im);
|
||||
|
||||
$im = new Imagick();
|
||||
$im->newImage(10, 10, new ImagickPixel('green'));
|
||||
$imagick->addImage($im);
|
||||
|
||||
$im = new Imagick();
|
||||
$im->newImage(10, 10, new ImagickPixel('blue'));
|
||||
$imagick->addImage($im);
|
||||
|
||||
$this->core = new Core($imagick);
|
||||
}
|
||||
|
||||
public function testAdd(): void
|
||||
{
|
||||
$imagick = new Imagick();
|
||||
$imagick->newImage(100, 100, new ImagickPixel('red'));
|
||||
$this->assertEquals(3, $this->core->count());
|
||||
$result = $this->core->add(new Frame($imagick));
|
||||
$this->assertEquals(4, $this->core->count());
|
||||
$this->assertInstanceOf(Core::class, $result);
|
||||
}
|
||||
|
||||
public function testCount(): void
|
||||
{
|
||||
$this->assertEquals(3, $this->core->count());
|
||||
}
|
||||
|
||||
public function testIterator(): void
|
||||
{
|
||||
foreach ($this->core as $frame) {
|
||||
$this->assertInstanceOf(Frame::class, $frame);
|
||||
}
|
||||
}
|
||||
|
||||
public function testNative(): void
|
||||
{
|
||||
$this->assertInstanceOf(Imagick::class, $this->core->native());
|
||||
}
|
||||
|
||||
public function testSetNative(): void
|
||||
{
|
||||
$imagick1 = new Imagick();
|
||||
$imagick1->newImage(10, 10, new ImagickPixel('red'));
|
||||
|
||||
$imagick2 = new Imagick();
|
||||
$imagick2->newImage(10, 10, new ImagickPixel('red'));
|
||||
|
||||
$core = new Core($imagick1);
|
||||
$this->assertEquals($imagick1, $core->native());
|
||||
$core->setNative($imagick2);
|
||||
$this->assertEquals($imagick2, $core->native());
|
||||
}
|
||||
|
||||
public function testFrame(): void
|
||||
{
|
||||
$this->assertInstanceOf(Frame::class, $this->core->frame(0));
|
||||
$this->assertInstanceOf(Frame::class, $this->core->frame(1));
|
||||
$this->assertInstanceOf(Frame::class, $this->core->frame(2));
|
||||
$this->expectException(AnimationException::class);
|
||||
$this->core->frame(3);
|
||||
}
|
||||
|
||||
public function testSetGetLoops(): void
|
||||
{
|
||||
$this->assertEquals(0, $this->core->loops());
|
||||
$result = $this->core->setLoops(12);
|
||||
$this->assertEquals(12, $this->core->loops());
|
||||
$this->assertInstanceOf(Core::class, $result);
|
||||
}
|
||||
|
||||
public function testHas(): void
|
||||
{
|
||||
$this->assertTrue($this->core->has(0));
|
||||
$this->assertTrue($this->core->has(1));
|
||||
$this->assertTrue($this->core->has(2));
|
||||
$this->assertFalse($this->core->has(3));
|
||||
}
|
||||
|
||||
public function testPush(): void
|
||||
{
|
||||
$im = new Imagick();
|
||||
$im->newImage(100, 100, new ImagickPixel('green'));
|
||||
$this->assertEquals(3, $this->core->count());
|
||||
$result = $this->core->push(new Frame($im));
|
||||
$this->assertEquals(4, $this->core->count());
|
||||
$this->assertEquals(4, $result->count());
|
||||
}
|
||||
|
||||
public function testGet(): void
|
||||
{
|
||||
$this->assertInstanceOf(Frame::class, $this->core->get(0));
|
||||
$this->assertInstanceOf(Frame::class, $this->core->get(1));
|
||||
$this->assertInstanceOf(Frame::class, $this->core->get(2));
|
||||
$this->assertNull($this->core->get(3));
|
||||
$this->assertEquals('foo', $this->core->get(3, 'foo'));
|
||||
}
|
||||
|
||||
public function testEmpty(): void
|
||||
{
|
||||
$result = $this->core->empty();
|
||||
$this->assertEquals(0, $this->core->count());
|
||||
$this->assertEquals(0, $result->count());
|
||||
}
|
||||
|
||||
public function testSlice(): void
|
||||
{
|
||||
$this->assertEquals(3, $this->core->count());
|
||||
$result = $this->core->slice(1, 2);
|
||||
$this->assertEquals(2, $this->core->count());
|
||||
$this->assertEquals(2, $result->count());
|
||||
}
|
||||
|
||||
public function testFirst(): void
|
||||
{
|
||||
$this->assertInstanceOf(Frame::class, $this->core->first());
|
||||
}
|
||||
|
||||
public function testLast(): void
|
||||
{
|
||||
$this->assertInstanceOf(Frame::class, $this->core->last());
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Decoders;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Intervention\Image\Drivers\Imagick\Decoders\Base64ImageDecoder;
|
||||
use Intervention\Image\Exceptions\DecoderException;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Decoders\Base64ImageDecoder::class)]
|
||||
final class Base64ImageDecoderTest extends BaseTestCase
|
||||
{
|
||||
protected Base64ImageDecoder $decoder;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->decoder = new Base64ImageDecoder();
|
||||
}
|
||||
|
||||
public function testDecode(): void
|
||||
{
|
||||
$result = $this->decoder->decode(
|
||||
base64_encode($this->getTestImageData('blue.gif'))
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
}
|
||||
|
||||
public function testDecoderInvalid(): void
|
||||
{
|
||||
$this->expectException(DecoderException::class);
|
||||
$this->decoder->decode('test');
|
||||
}
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Decoders;
|
||||
|
||||
use Intervention\Image\Colors\Cmyk\Colorspace as CmykColorspace;
|
||||
use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace;
|
||||
use Intervention\Image\Drivers\Imagick\Decoders\BinaryImageDecoder;
|
||||
use Intervention\Image\Exceptions\DecoderException;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use stdClass;
|
||||
|
||||
final class BinaryImageDecoderTest extends BaseTestCase
|
||||
{
|
||||
public function testDecodePng(): void
|
||||
{
|
||||
$decoder = new BinaryImageDecoder();
|
||||
$image = $decoder->decode(file_get_contents($this->getTestImagePath('tile.png')));
|
||||
$this->assertInstanceOf(Image::class, $image);
|
||||
$this->assertInstanceOf(RgbColorspace::class, $image->colorspace());
|
||||
$this->assertEquals(16, $image->width());
|
||||
$this->assertEquals(16, $image->height());
|
||||
$this->assertCount(1, $image);
|
||||
}
|
||||
|
||||
public function testDecodeGif(): void
|
||||
{
|
||||
$decoder = new BinaryImageDecoder();
|
||||
$image = $decoder->decode(file_get_contents($this->getTestImagePath('red.gif')));
|
||||
$this->assertInstanceOf(Image::class, $image);
|
||||
$this->assertEquals(16, $image->width());
|
||||
$this->assertEquals(16, $image->height());
|
||||
$this->assertCount(1, $image);
|
||||
}
|
||||
|
||||
public function testDecodeAnimatedGif(): void
|
||||
{
|
||||
$decoder = new BinaryImageDecoder();
|
||||
$image = $decoder->decode(file_get_contents($this->getTestImagePath('cats.gif')));
|
||||
$this->assertInstanceOf(Image::class, $image);
|
||||
$this->assertEquals(75, $image->width());
|
||||
$this->assertEquals(50, $image->height());
|
||||
$this->assertCount(4, $image);
|
||||
}
|
||||
|
||||
public function testDecodeJpegWithExif(): void
|
||||
{
|
||||
$decoder = new BinaryImageDecoder();
|
||||
$image = $decoder->decode(file_get_contents($this->getTestImagePath('exif.jpg')));
|
||||
$this->assertInstanceOf(Image::class, $image);
|
||||
$this->assertEquals(16, $image->width());
|
||||
$this->assertEquals(16, $image->height());
|
||||
$this->assertCount(1, $image);
|
||||
$this->assertEquals('Oliver Vogel', $image->exif('IFD0.Artist'));
|
||||
}
|
||||
|
||||
public function testDecodeCmykImage(): void
|
||||
{
|
||||
$decoder = new BinaryImageDecoder();
|
||||
$image = $decoder->decode(file_get_contents($this->getTestImagePath('cmyk.jpg')));
|
||||
$this->assertInstanceOf(Image::class, $image);
|
||||
$this->assertInstanceOf(CmykColorspace::class, $image->colorspace());
|
||||
}
|
||||
|
||||
public function testDecodeNonString(): void
|
||||
{
|
||||
$decoder = new BinaryImageDecoder();
|
||||
$this->expectException(DecoderException::class);
|
||||
$decoder->decode(new stdClass());
|
||||
}
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Decoders;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Intervention\Image\Drivers\Imagick\Decoders\DataUriImageDecoder;
|
||||
use Intervention\Image\Exceptions\DecoderException;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use stdClass;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Decoders\DataUriImageDecoder::class)]
|
||||
final class DataUriImageDecoderTest extends BaseTestCase
|
||||
{
|
||||
protected DataUriImageDecoder $decoder;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->decoder = new DataUriImageDecoder();
|
||||
}
|
||||
|
||||
public function testDecode(): void
|
||||
{
|
||||
$result = $this->decoder->decode(
|
||||
sprintf('data:image/jpeg;base64,%s', base64_encode($this->getTestImageData('blue.gif')))
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
}
|
||||
|
||||
public function testDecoderNonString(): void
|
||||
{
|
||||
$this->expectException(DecoderException::class);
|
||||
$this->decoder->decode(new stdClass());
|
||||
}
|
||||
|
||||
public function testDecoderInvalid(): void
|
||||
{
|
||||
$this->expectException(DecoderException::class);
|
||||
$this->decoder->decode('invalid');
|
||||
}
|
||||
|
||||
public function testDecoderNonImage(): void
|
||||
{
|
||||
$this->expectException(DecoderException::class);
|
||||
$this->decoder->decode('data:text/plain;charset=utf-8,test');
|
||||
}
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Decoders;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Intervention\Image\Drivers\Imagick\Decoders\FilePathImageDecoder;
|
||||
use Intervention\Image\Exceptions\DecoderException;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use stdClass;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Decoders\FilePathImageDecoder::class)]
|
||||
final class FilePathImageDecoderTest extends BaseTestCase
|
||||
{
|
||||
protected FilePathImageDecoder $decoder;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->decoder = new FilePathImageDecoder();
|
||||
}
|
||||
|
||||
public function testDecode(): void
|
||||
{
|
||||
$result = $this->decoder->decode(
|
||||
$this->getTestImagePath()
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
}
|
||||
|
||||
public function testDecoderNonString(): void
|
||||
{
|
||||
$this->expectException(DecoderException::class);
|
||||
$this->decoder->decode(new stdClass());
|
||||
}
|
||||
|
||||
public function testDecoderNoPath(): void
|
||||
{
|
||||
$this->expectException(DecoderException::class);
|
||||
$this->decoder->decode('no-path');
|
||||
}
|
||||
|
||||
public function testDecoderTooLongPath(): void
|
||||
{
|
||||
$this->expectException(DecoderException::class);
|
||||
$this->decoder->decode(str_repeat('x', PHP_MAXPATHLEN + 1));
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Decoders;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Intervention\Image\Drivers\Imagick\Decoders\FilePointerImageDecoder;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Decoders\FilePointerImageDecoder::class)]
|
||||
final class FilePointerImageDecoderTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testDecode(): void
|
||||
{
|
||||
$decoder = new FilePointerImageDecoder();
|
||||
$fp = fopen($this->getTestImagePath('test.jpg'), 'r');
|
||||
$result = $decoder->decode($fp);
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Decoders;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Intervention\Image\Drivers\Imagick\Decoders\ImageObjectDecoder;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Decoders\ImageObjectDecoder::class)]
|
||||
final class ImageObjectDecoderTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testDecode(): void
|
||||
{
|
||||
$decoder = new ImageObjectDecoder();
|
||||
$result = $decoder->decode($this->readTestImage('blue.gif'));
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Decoders;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Intervention\Image\Drivers\Imagick\Decoders\SplFileInfoImageDecoder;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use SplFileInfo;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Decoders\SplFileInfoImageDecoder::class)]
|
||||
final class SplFileInfoImageDecoderTest extends BaseTestCase
|
||||
{
|
||||
public function testDecode(): void
|
||||
{
|
||||
$decoder = new SplFileInfoImageDecoder();
|
||||
$result = $decoder->decode(
|
||||
new SplFileInfo($this->getTestImagePath('blue.gif'))
|
||||
);
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
}
|
||||
}
|
84
tests/Unit/Drivers/Imagick/DriverTest.php
Normal file
84
tests/Unit/Drivers/Imagick/DriverTest.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick;
|
||||
|
||||
use Intervention\Image\Colors\Rgb\Colorspace;
|
||||
use Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder;
|
||||
use Intervention\Image\Drivers\Imagick\Driver;
|
||||
use Intervention\Image\Interfaces\ColorInterface;
|
||||
use Intervention\Image\Interfaces\ColorProcessorInterface;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
|
||||
final class DriverTest extends BaseTestCase
|
||||
{
|
||||
protected Driver $driver;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->driver = new Driver();
|
||||
}
|
||||
|
||||
public function testId(): void
|
||||
{
|
||||
$this->assertEquals('Imagick', $this->driver->id());
|
||||
}
|
||||
|
||||
public function testCreateImage(): void
|
||||
{
|
||||
$image = $this->driver->createImage(3, 2);
|
||||
$this->assertInstanceOf(ImageInterface::class, $image);
|
||||
$this->assertEquals(3, $image->width());
|
||||
$this->assertEquals(2, $image->height());
|
||||
}
|
||||
|
||||
public function testCreateAnimation(): void
|
||||
{
|
||||
$image = $this->driver->createAnimation(function ($animation) {
|
||||
$animation->add($this->getTestImagePath('red.gif'), .25);
|
||||
$animation->add($this->getTestImagePath('green.gif'), .25);
|
||||
})->setLoops(5);
|
||||
$this->assertInstanceOf(ImageInterface::class, $image);
|
||||
|
||||
$this->assertEquals(16, $image->width());
|
||||
$this->assertEquals(16, $image->height());
|
||||
$this->assertEquals(5, $image->loops());
|
||||
$this->assertEquals(2, $image->count());
|
||||
}
|
||||
|
||||
public function testHandleInputImage(): void
|
||||
{
|
||||
$result = $this->driver->handleInput($this->getTestImagePath('test.jpg'));
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testHandleInputColor(): void
|
||||
{
|
||||
$result = $this->driver->handleInput('ffffff');
|
||||
$this->assertInstanceOf(ColorInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testHandleInputObjects(): void
|
||||
{
|
||||
$result = $this->driver->handleInput('ffffff', [
|
||||
new HexColorDecoder()
|
||||
]);
|
||||
$this->assertInstanceOf(ColorInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testHandleInputClassnames(): void
|
||||
{
|
||||
$result = $this->driver->handleInput('ffffff', [
|
||||
HexColorDecoder::class
|
||||
]);
|
||||
$this->assertInstanceOf(ColorInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testColorProcessor(): void
|
||||
{
|
||||
$result = $this->driver->colorProcessor(new Colorspace());
|
||||
$this->assertInstanceOf(ColorProcessorInterface::class, $result);
|
||||
}
|
||||
}
|
40
tests/Unit/Drivers/Imagick/Encoders/AvifEncoderTest.php
Normal file
40
tests/Unit/Drivers/Imagick/Encoders/AvifEncoderTest.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Imagick;
|
||||
use ImagickPixel;
|
||||
use Intervention\Image\Drivers\Imagick\Core;
|
||||
use Intervention\Image\Drivers\Imagick\Driver;
|
||||
use Intervention\Image\Encoders\AvifEncoder;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Encoders\AvifEncoder::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Encoders\AvifEncoder::class)]
|
||||
final class AvifEncoderTest extends BaseTestCase
|
||||
{
|
||||
protected function getTestImage(): Image
|
||||
{
|
||||
$imagick = new Imagick();
|
||||
$imagick->newImage(3, 2, new ImagickPixel('red'), 'png');
|
||||
|
||||
return new Image(
|
||||
new Driver(),
|
||||
new Core($imagick)
|
||||
);
|
||||
}
|
||||
|
||||
public function testEncode(): void
|
||||
{
|
||||
$image = $this->getTestImage();
|
||||
$encoder = new AvifEncoder(10);
|
||||
$result = $encoder->encode($image);
|
||||
$this->assertMediaType('image/avif', (string) $result);
|
||||
}
|
||||
}
|
43
tests/Unit/Drivers/Imagick/Encoders/BmpEncoderTest.php
Normal file
43
tests/Unit/Drivers/Imagick/Encoders/BmpEncoderTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Imagick;
|
||||
use ImagickPixel;
|
||||
use Intervention\Image\Drivers\Imagick\Core;
|
||||
use Intervention\Image\Drivers\Imagick\Driver;
|
||||
use Intervention\Image\Encoders\BmpEncoder;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Encoders\BmpEncoder::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Encoders\BmpEncoder::class)]
|
||||
final class BmpEncoderTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
protected function getTestImage(): Image
|
||||
{
|
||||
$imagick = new Imagick();
|
||||
$imagick->newImage(3, 2, new ImagickPixel('red'), 'png');
|
||||
|
||||
return new Image(
|
||||
new Driver(),
|
||||
new Core($imagick)
|
||||
);
|
||||
}
|
||||
|
||||
public function testEncode(): void
|
||||
{
|
||||
$image = $this->getTestImage();
|
||||
$encoder = new BmpEncoder();
|
||||
$result = $encoder->encode($image);
|
||||
$this->assertMediaType(['image/bmp', 'image/x-ms-bmp'], (string) $result);
|
||||
}
|
||||
}
|
57
tests/Unit/Drivers/Imagick/Encoders/GifEncoderTest.php
Normal file
57
tests/Unit/Drivers/Imagick/Encoders/GifEncoderTest.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Imagick;
|
||||
use ImagickPixel;
|
||||
use Intervention\Image\Drivers\Imagick\Core;
|
||||
use Intervention\Image\Drivers\Imagick\Driver;
|
||||
use Intervention\Image\Encoders\GifEncoder;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Encoders\GifEncoder::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Encoders\GifEncoder::class)]
|
||||
final class GifEncoderTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
protected function getTestImage(): Image
|
||||
{
|
||||
$imagick = new Imagick();
|
||||
|
||||
$frame = new Imagick();
|
||||
$frame->newImage(30, 20, new ImagickPixel('red'), 'png');
|
||||
$frame->setImageDelay(50);
|
||||
$imagick->addImage($frame);
|
||||
|
||||
$frame = new Imagick();
|
||||
$frame->newImage(30, 20, new ImagickPixel('green'), 'png');
|
||||
$frame->setImageDelay(50);
|
||||
$imagick->addImage($frame);
|
||||
|
||||
$frame = new Imagick();
|
||||
$frame->newImage(30, 20, new ImagickPixel('blue'), 'png');
|
||||
$frame->setImageDelay(50);
|
||||
$imagick->addImage($frame);
|
||||
|
||||
return new Image(
|
||||
new Driver(),
|
||||
new Core($imagick)
|
||||
);
|
||||
}
|
||||
|
||||
public function testEncode(): void
|
||||
{
|
||||
$image = $this->getTestImage();
|
||||
$encoder = new GifEncoder();
|
||||
$result = $encoder->encode($image);
|
||||
$this->assertMediaType('image/gif', (string) $result);
|
||||
}
|
||||
}
|
43
tests/Unit/Drivers/Imagick/Encoders/HeicEncoderTest.php
Normal file
43
tests/Unit/Drivers/Imagick/Encoders/HeicEncoderTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Imagick;
|
||||
use ImagickPixel;
|
||||
use Intervention\Image\Drivers\Imagick\Core;
|
||||
use Intervention\Image\Drivers\Imagick\Driver;
|
||||
use Intervention\Image\Encoders\HeicEncoder;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Encoders\HeicEncoder::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Encoders\HeicEncoder::class)]
|
||||
final class HeicEncoderTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
protected function getTestImage(): Image
|
||||
{
|
||||
$imagick = new Imagick();
|
||||
$imagick->newImage(3, 2, new ImagickPixel('red'), 'jpg');
|
||||
|
||||
return new Image(
|
||||
new Driver(),
|
||||
new Core($imagick)
|
||||
);
|
||||
}
|
||||
|
||||
public function testEncode(): void
|
||||
{
|
||||
$image = $this->getTestImage();
|
||||
$encoder = new HeicEncoder(75);
|
||||
$result = $encoder->encode($image);
|
||||
$this->assertMediaType('image/heic', (string) $result);
|
||||
}
|
||||
}
|
40
tests/Unit/Drivers/Imagick/Encoders/Jpeg2000EncoderTest.php
Normal file
40
tests/Unit/Drivers/Imagick/Encoders/Jpeg2000EncoderTest.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Imagick;
|
||||
use ImagickPixel;
|
||||
use Intervention\Image\Drivers\Imagick\Core;
|
||||
use Intervention\Image\Drivers\Imagick\Driver;
|
||||
use Intervention\Image\Encoders\Jpeg2000Encoder;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Encoders\Jpeg2000Encoder::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Encoders\Jpeg2000Encoder::class)]
|
||||
final class Jpeg2000EncoderTest extends BaseTestCase
|
||||
{
|
||||
protected function getTestImage(): Image
|
||||
{
|
||||
$imagick = new Imagick();
|
||||
$imagick->newImage(3, 2, new ImagickPixel('red'), 'png');
|
||||
|
||||
return new Image(
|
||||
new Driver(),
|
||||
new Core($imagick)
|
||||
);
|
||||
}
|
||||
|
||||
public function testEncode(): void
|
||||
{
|
||||
$image = $this->getTestImage();
|
||||
$encoder = new Jpeg2000Encoder(75);
|
||||
$result = $encoder->encode($image);
|
||||
$this->assertMediaType('image/jp2', (string) $result);
|
||||
}
|
||||
}
|
40
tests/Unit/Drivers/Imagick/Encoders/JpegEncoderTest.php
Normal file
40
tests/Unit/Drivers/Imagick/Encoders/JpegEncoderTest.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Imagick;
|
||||
use ImagickPixel;
|
||||
use Intervention\Image\Drivers\Imagick\Core;
|
||||
use Intervention\Image\Drivers\Imagick\Driver;
|
||||
use Intervention\Image\Encoders\JpegEncoder;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Encoders\JpegEncoder::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Encoders\JpegEncoder::class)]
|
||||
final class JpegEncoderTest extends BaseTestCase
|
||||
{
|
||||
protected function getTestImage(): Image
|
||||
{
|
||||
$imagick = new Imagick();
|
||||
$imagick->newImage(3, 2, new ImagickPixel('red'), 'png');
|
||||
|
||||
return new Image(
|
||||
new Driver(),
|
||||
new Core($imagick)
|
||||
);
|
||||
}
|
||||
|
||||
public function testEncode(): void
|
||||
{
|
||||
$image = $this->getTestImage();
|
||||
$encoder = new JpegEncoder(75);
|
||||
$result = $encoder->encode($image);
|
||||
$this->assertMediaType('image/jpeg', (string) $result);
|
||||
}
|
||||
}
|
43
tests/Unit/Drivers/Imagick/Encoders/PngEncoderTest.php
Normal file
43
tests/Unit/Drivers/Imagick/Encoders/PngEncoderTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Imagick;
|
||||
use ImagickPixel;
|
||||
use Intervention\Image\Drivers\Imagick\Core;
|
||||
use Intervention\Image\Drivers\Imagick\Driver;
|
||||
use Intervention\Image\Encoders\PngEncoder;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Encoders\PngEncoder::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Encoders\PngEncoder::class)]
|
||||
final class PngEncoderTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
protected function getTestImage(): Image
|
||||
{
|
||||
$imagick = new Imagick();
|
||||
$imagick->newImage(3, 2, new ImagickPixel('red'), 'jpg');
|
||||
|
||||
return new Image(
|
||||
new Driver(),
|
||||
new Core($imagick)
|
||||
);
|
||||
}
|
||||
|
||||
public function testEncode(): void
|
||||
{
|
||||
$image = $this->getTestImage();
|
||||
$encoder = new PngEncoder(75);
|
||||
$result = $encoder->encode($image);
|
||||
$this->assertMediaType('image/png', (string) $result);
|
||||
}
|
||||
}
|
40
tests/Unit/Drivers/Imagick/Encoders/TiffEncoderTest.php
Normal file
40
tests/Unit/Drivers/Imagick/Encoders/TiffEncoderTest.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Imagick;
|
||||
use ImagickPixel;
|
||||
use Intervention\Image\Drivers\Imagick\Core;
|
||||
use Intervention\Image\Drivers\Imagick\Driver;
|
||||
use Intervention\Image\Encoders\TiffEncoder;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Encoders\TiffEncoder::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Encoders\TiffEncoder::class)]
|
||||
final class TiffEncoderTest extends BaseTestCase
|
||||
{
|
||||
protected function getTestImage(): Image
|
||||
{
|
||||
$imagick = new Imagick();
|
||||
$imagick->newImage(3, 2, new ImagickPixel('red'), 'png');
|
||||
|
||||
return new Image(
|
||||
new Driver(),
|
||||
new Core($imagick)
|
||||
);
|
||||
}
|
||||
|
||||
public function testEncode(): void
|
||||
{
|
||||
$image = $this->getTestImage();
|
||||
$encoder = new TiffEncoder();
|
||||
$result = $encoder->encode($image);
|
||||
$this->assertMediaType('image/tiff', (string) $result);
|
||||
}
|
||||
}
|
40
tests/Unit/Drivers/Imagick/Encoders/WebpEncoderTest.php
Normal file
40
tests/Unit/Drivers/Imagick/Encoders/WebpEncoderTest.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Imagick;
|
||||
use ImagickPixel;
|
||||
use Intervention\Image\Drivers\Imagick\Core;
|
||||
use Intervention\Image\Drivers\Imagick\Driver;
|
||||
use Intervention\Image\Encoders\WebpEncoder;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Encoders\WebpEncoder::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Encoders\WebpEncoder::class)]
|
||||
final class WebpEncoderTest extends BaseTestCase
|
||||
{
|
||||
protected function getTestImage(): Image
|
||||
{
|
||||
$imagick = new Imagick();
|
||||
$imagick->newImage(3, 2, new ImagickPixel('red'), 'png');
|
||||
|
||||
return new Image(
|
||||
new Driver(),
|
||||
new Core($imagick)
|
||||
);
|
||||
}
|
||||
|
||||
public function testEncode(): void
|
||||
{
|
||||
$image = $this->getTestImage();
|
||||
$encoder = new WebpEncoder(75);
|
||||
$result = $encoder->encode($image);
|
||||
$this->assertMediaType('image/webp', (string) $result);
|
||||
}
|
||||
}
|
21
tests/Unit/Drivers/Imagick/FontProcessorTest.php
Normal file
21
tests/Unit/Drivers/Imagick/FontProcessorTest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick;
|
||||
|
||||
use Intervention\Image\Drivers\Imagick\FontProcessor;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Typography\Font;
|
||||
|
||||
final class FontProcessorTest extends BaseTestCase
|
||||
{
|
||||
public function testNativeFontSize(): void
|
||||
{
|
||||
$processor = new FontProcessor();
|
||||
$font = new Font();
|
||||
$font->setSize(14.2);
|
||||
$size = $processor->nativeFontSize($font);
|
||||
$this->assertEquals(14.2, $size);
|
||||
}
|
||||
}
|
102
tests/Unit/Drivers/Imagick/FrameTest.php
Normal file
102
tests/Unit/Drivers/Imagick/FrameTest.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Imagick;
|
||||
use ImagickPixel;
|
||||
use Intervention\Image\Drivers\Imagick\Driver;
|
||||
use Intervention\Image\Drivers\Imagick\Frame;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Geometry\Rectangle;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Frame::class)]
|
||||
final class FrameTest extends BaseTestCase
|
||||
{
|
||||
protected function getTestFrame(): Frame
|
||||
{
|
||||
$imagick = new Imagick();
|
||||
$imagick->newImage(3, 2, new ImagickPixel('red'), 'png');
|
||||
$imagick->setImageDelay(125); // 1.25 seconds
|
||||
$imagick->setImageDispose(5);
|
||||
$imagick->setImagePage(3, 2, 8, 9);
|
||||
|
||||
return new Frame($imagick);
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$frame = $this->getTestFrame();
|
||||
$this->assertInstanceOf(Frame::class, $frame);
|
||||
}
|
||||
|
||||
public function testGetSize(): void
|
||||
{
|
||||
$frame = $this->getTestFrame();
|
||||
$this->assertInstanceOf(Rectangle::class, $frame->size());
|
||||
}
|
||||
|
||||
public function testSetGetDelay(): void
|
||||
{
|
||||
$frame = $this->getTestFrame();
|
||||
$this->assertEquals(1.25, $frame->delay());
|
||||
|
||||
$result = $frame->setDelay(2.5);
|
||||
$this->assertInstanceOf(Frame::class, $result);
|
||||
$this->assertEquals(2.5, $frame->delay());
|
||||
$this->assertEquals(250, $frame->native()->getImageDelay());
|
||||
}
|
||||
|
||||
public function testSetGetDispose(): void
|
||||
{
|
||||
$frame = $this->getTestFrame();
|
||||
$this->assertEquals(5, $frame->dispose());
|
||||
|
||||
$result = $frame->setDispose(100);
|
||||
$this->assertInstanceOf(Frame::class, $result);
|
||||
$this->assertEquals(100, $frame->dispose());
|
||||
}
|
||||
|
||||
public function testSetGetOffsetLeft(): void
|
||||
{
|
||||
$frame = $this->getTestFrame();
|
||||
$this->assertEquals(8, $frame->offsetLeft());
|
||||
|
||||
$result = $frame->setOffsetLeft(100);
|
||||
$this->assertInstanceOf(Frame::class, $result);
|
||||
$this->assertEquals(100, $frame->offsetLeft());
|
||||
}
|
||||
|
||||
public function testSetGetOffsetTop(): void
|
||||
{
|
||||
$frame = $this->getTestFrame();
|
||||
$this->assertEquals(9, $frame->offsetTop());
|
||||
|
||||
$result = $frame->setOffsetTop(100);
|
||||
$this->assertInstanceOf(Frame::class, $result);
|
||||
$this->assertEquals(100, $frame->offsetTop());
|
||||
}
|
||||
|
||||
public function testSetGetOffset(): void
|
||||
{
|
||||
$frame = $this->getTestFrame();
|
||||
$this->assertEquals(8, $frame->offsetLeft());
|
||||
$this->assertEquals(9, $frame->offsetTop());
|
||||
|
||||
$result = $frame->setOffset(100, 200);
|
||||
$this->assertInstanceOf(Frame::class, $result);
|
||||
$this->assertEquals(100, $frame->offsetLeft());
|
||||
$this->assertEquals(200, $frame->offsetTop());
|
||||
}
|
||||
|
||||
public function testToImage(): void
|
||||
{
|
||||
$frame = $this->getTestFrame();
|
||||
$this->assertInstanceOf(Image::class, $frame->toImage(new Driver()));
|
||||
}
|
||||
}
|
385
tests/Unit/Drivers/Imagick/ImageTest.php
Normal file
385
tests/Unit/Drivers/Imagick/ImageTest.php
Normal file
@@ -0,0 +1,385 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick;
|
||||
|
||||
use Imagick;
|
||||
use Intervention\Image\Analyzers\WidthAnalyzer;
|
||||
use Intervention\Image\Collection;
|
||||
use Intervention\Image\Colors\Cmyk\Colorspace as CmykColorspace;
|
||||
use Intervention\Image\Colors\Rgb\Color;
|
||||
use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace;
|
||||
use Intervention\Image\Drivers\Imagick\Core;
|
||||
use Intervention\Image\Drivers\Imagick\Driver;
|
||||
use Intervention\Image\Drivers\Imagick\Frame;
|
||||
use Intervention\Image\EncodedImage;
|
||||
use Intervention\Image\Encoders\PngEncoder;
|
||||
use Intervention\Image\Exceptions\ColorException;
|
||||
use Intervention\Image\Exceptions\EncoderException;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Interfaces\ColorInterface;
|
||||
use Intervention\Image\Interfaces\ColorspaceInterface;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Interfaces\ResolutionInterface;
|
||||
use Intervention\Image\Interfaces\SizeInterface;
|
||||
use Intervention\Image\Modifiers\GreyscaleModifier;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
final class ImageTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
protected Image $image;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$imagick = new Imagick();
|
||||
$imagick->readImage($this->getTestImagePath('animation.gif'));
|
||||
$this->image = new Image(
|
||||
new Driver(),
|
||||
new Core($imagick),
|
||||
new Collection([
|
||||
'test' => 'foo'
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
public function testClone(): void
|
||||
{
|
||||
$image = $this->readTestImage('gradient.gif');
|
||||
$clone = clone $image;
|
||||
|
||||
$this->assertEquals(16, $image->width());
|
||||
$this->assertEquals(16, $clone->width());
|
||||
$result = $clone->crop(4, 4);
|
||||
$this->assertEquals(16, $image->width());
|
||||
$this->assertEquals(4, $clone->width());
|
||||
$this->assertEquals(4, $result->width());
|
||||
|
||||
$this->assertEquals('ff0000', $image->pickColor(0, 0)->toHex());
|
||||
$this->assertTransparency($image->pickColor(1, 0));
|
||||
|
||||
$this->assertEquals('ff0000', $clone->pickColor(0, 0)->toHex());
|
||||
$this->assertTransparency($clone->pickColor(1, 0));
|
||||
}
|
||||
|
||||
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 testSetGetLoops(): void
|
||||
{
|
||||
$this->assertEquals(3, $this->image->loops());
|
||||
$result = $this->image->setLoops(10);
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
$this->assertEquals(10, $this->image->loops());
|
||||
}
|
||||
|
||||
public function testRemoveAnimation(): void
|
||||
{
|
||||
$this->assertTrue($this->image->isAnimated());
|
||||
$result = $this->image->removeAnimation();
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
$this->assertFalse($this->image->isAnimated());
|
||||
}
|
||||
|
||||
public function testSliceAnimation(): void
|
||||
{
|
||||
$this->assertEquals(8, $this->image->count());
|
||||
$result = $this->image->sliceAnimation(0, 2);
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
$this->assertEquals(2, $this->image->count());
|
||||
}
|
||||
|
||||
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 testAutoEncode(): void
|
||||
{
|
||||
$result = $this->readTestImage('blue.gif')->encode();
|
||||
$this->assertInstanceOf(EncodedImage::class, $result);
|
||||
$this->assertMediaType('image/gif', (string) $result);
|
||||
}
|
||||
|
||||
public function testEncodeByMediaType(): void
|
||||
{
|
||||
$result = $this->readTestImage('blue.gif')->encodeByMediaType();
|
||||
$this->assertInstanceOf(EncodedImage::class, $result);
|
||||
$this->assertMediaType('image/gif', (string) $result);
|
||||
|
||||
$result = $this->readTestImage('blue.gif')->encodeByMediaType('image/png');
|
||||
$this->assertInstanceOf(EncodedImage::class, $result);
|
||||
$this->assertMediaType('image/png', (string) $result);
|
||||
}
|
||||
|
||||
public function testEncodeByExtension(): void
|
||||
{
|
||||
$result = $this->readTestImage('blue.gif')->encodeByExtension();
|
||||
$this->assertInstanceOf(EncodedImage::class, $result);
|
||||
$this->assertMediaType('image/gif', (string) $result);
|
||||
|
||||
$result = $this->readTestImage('blue.gif')->encodeByExtension('png');
|
||||
$this->assertInstanceOf(EncodedImage::class, $result);
|
||||
$this->assertMediaType('image/png', (string) $result);
|
||||
}
|
||||
|
||||
public function testEncodeByPath(): void
|
||||
{
|
||||
$result = $this->readTestImage('blue.gif')->encodeByPath();
|
||||
$this->assertInstanceOf(EncodedImage::class, $result);
|
||||
$this->assertMediaType('image/gif', (string) $result);
|
||||
|
||||
$result = $this->readTestImage('blue.gif')->encodeByPath('foo/bar.png');
|
||||
$this->assertInstanceOf(EncodedImage::class, $result);
|
||||
$this->assertMediaType('image/png', (string) $result);
|
||||
}
|
||||
|
||||
public function testSaveAsFormat(): void
|
||||
{
|
||||
$path = __DIR__ . '/tmp.png';
|
||||
$result = $this->readTestImage('blue.gif')->save($path);
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
$this->assertFileExists($path);
|
||||
$this->assertMediaType('image/png', file_get_contents($path));
|
||||
unlink($path);
|
||||
}
|
||||
|
||||
public function testSaveFallback(): void
|
||||
{
|
||||
$path = __DIR__ . '/tmp.unknown';
|
||||
$result = $this->readTestImage('blue.gif')->save($path);
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
$this->assertFileExists($path);
|
||||
$this->assertMediaType('image/gif', file_get_contents($path));
|
||||
unlink($path);
|
||||
}
|
||||
|
||||
public function testSaveUndeterminedPath(): void
|
||||
{
|
||||
$this->expectException(EncoderException::class);
|
||||
$this->createTestImage(2, 3)->save();
|
||||
}
|
||||
|
||||
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 testSetGetColorspace(): void
|
||||
{
|
||||
$this->assertInstanceOf(ColorspaceInterface::class, $this->image->colorspace());
|
||||
$this->assertInstanceOf(RgbColorspace::class, $this->image->colorspace());
|
||||
$result = $this->image->setColorspace(CmykColorspace::class);
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
$this->assertInstanceOf(CmykColorspace::class, $this->image->colorspace());
|
||||
}
|
||||
|
||||
public function testSetGetResolution(): void
|
||||
{
|
||||
$resolution = $this->image->resolution();
|
||||
$this->assertInstanceOf(ResolutionInterface::class, $resolution);
|
||||
$this->assertEquals(0, $resolution->x());
|
||||
$this->assertEquals(0, $resolution->y());
|
||||
$result = $this->image->setResolution(300, 300);
|
||||
$resolution = $this->image->resolution();
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
$this->assertEquals(300, $resolution->x());
|
||||
$this->assertEquals(300, $resolution->y());
|
||||
}
|
||||
|
||||
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 testReduceColors(): void
|
||||
{
|
||||
$image = $this->readTestImage();
|
||||
$result = $image->reduceColors(8);
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testSharpen(): void
|
||||
{
|
||||
$this->assertInstanceOf(Image::class, $this->image->sharpen(12));
|
||||
}
|
||||
|
||||
public function testSetGetBlendingColor(): void
|
||||
{
|
||||
$image = $this->readTestImage('gradient.gif');
|
||||
$this->assertInstanceOf(ColorInterface::class, $image->blendingColor());
|
||||
$this->assertColor(255, 255, 255, 0, $image->blendingColor());
|
||||
$result = $image->setBlendingColor(new Color(1, 2, 3, 4));
|
||||
$this->assertColor(1, 2, 3, 4, $result->blendingColor());
|
||||
$this->assertColor(1, 2, 3, 4, $image->blendingColor());
|
||||
}
|
||||
|
||||
public function testBlendTransparency(): void
|
||||
{
|
||||
$image = $this->readTestImage('gradient.gif');
|
||||
$this->assertColor(0, 0, 0, 0, $image->pickColor(1, 0));
|
||||
$result = $image->blendTransparency('ff5500');
|
||||
$this->assertColor(255, 85, 0, 255, $image->pickColor(1, 0));
|
||||
$this->assertColor(255, 85, 0, 255, $result->pickColor(1, 0));
|
||||
}
|
||||
|
||||
public function testToJpeg(): void
|
||||
{
|
||||
$this->assertMediaType('image/jpeg', (string) $this->image->toJpeg());
|
||||
$this->assertMediaType('image/jpeg', (string) $this->image->toJpg());
|
||||
}
|
||||
|
||||
public function testToJpeg2000(): void
|
||||
{
|
||||
$this->assertMediaType('image/jp2', (string) $this->image->toJpeg2000());
|
||||
$this->assertMediaType('image/jp2', (string) $this->image->toJp2());
|
||||
}
|
||||
|
||||
public function testToPng(): void
|
||||
{
|
||||
$this->assertMediaType('image/png', (string) $this->image->toPng());
|
||||
}
|
||||
|
||||
public function testToGif(): void
|
||||
{
|
||||
$this->assertMediaType('image/gif', (string) $this->image->toGif());
|
||||
}
|
||||
|
||||
public function testToWebp(): void
|
||||
{
|
||||
$this->assertMediaType('image/webp', (string) $this->image->toWebp());
|
||||
}
|
||||
|
||||
public function testToBitmap(): void
|
||||
{
|
||||
$this->assertMediaTypeBitmap((string) $this->image->toBitmap());
|
||||
$this->assertMediaTypeBitmap((string) $this->image->toBmp());
|
||||
}
|
||||
|
||||
public function testToAvif(): void
|
||||
{
|
||||
$this->assertMediaType('image/avif', (string) $this->image->toAvif());
|
||||
}
|
||||
|
||||
public function testToTiff(): void
|
||||
{
|
||||
$this->assertMediaType('image/tiff', (string) $this->image->toTiff());
|
||||
$this->assertMediaType('image/tiff', (string) $this->image->toTif());
|
||||
}
|
||||
|
||||
public function testToHeic(): void
|
||||
{
|
||||
$this->assertMediaType('image/heic', (string) $this->image->toHeic());
|
||||
}
|
||||
|
||||
public function testInvert(): void
|
||||
{
|
||||
$image = $this->readTestImage('trim.png');
|
||||
$this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex());
|
||||
$this->assertEquals('ffa601', $image->pickColor(25, 25)->toHex());
|
||||
$result = $image->invert();
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
$this->assertEquals('ff510f', $image->pickColor(0, 0)->toHex());
|
||||
$this->assertEquals('0059fe', $image->pickColor(25, 25)->toHex());
|
||||
}
|
||||
|
||||
public function testPixelate(): void
|
||||
{
|
||||
$image = $this->readTestImage('trim.png');
|
||||
$this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex());
|
||||
$this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex());
|
||||
|
||||
$result = $image->pixelate(10);
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
|
||||
list($r, $g, $b) = $image->pickColor(0, 0)->toArray();
|
||||
$this->assertEquals(0, $r);
|
||||
$this->assertEquals(174, $g);
|
||||
$this->assertEquals(240, $b);
|
||||
|
||||
list($r, $g, $b) = $image->pickColor(14, 14)->toArray();
|
||||
$this->assertEquals(107, $r);
|
||||
$this->assertEquals(171, $g);
|
||||
$this->assertEquals(140, $b);
|
||||
}
|
||||
|
||||
public function testGreyscale(): void
|
||||
{
|
||||
$image = $this->readTestImage('trim.png');
|
||||
$this->assertFalse($image->pickColor(0, 0)->isGreyscale());
|
||||
$result = $image->greyscale();
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
$this->assertTrue($image->pickColor(0, 0)->isGreyscale());
|
||||
}
|
||||
|
||||
public function testBrightness(): void
|
||||
{
|
||||
$image = $this->readTestImage('trim.png');
|
||||
$this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex());
|
||||
$result = $image->brightness(30);
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
$this->assertEquals('39c9ff', $image->pickColor(14, 14)->toHex());
|
||||
}
|
||||
}
|
146
tests/Unit/Drivers/Imagick/InputHandlerTest.php
Normal file
146
tests/Unit/Drivers/Imagick/InputHandlerTest.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use Intervention\Image\Colors\Cmyk\Color as CmykColor;
|
||||
use Intervention\Image\Colors\Hsv\Color as HsvColor;
|
||||
use Intervention\Image\Colors\Rgb\Color as RgbColor;
|
||||
use Intervention\Image\Drivers\Imagick\InputHandler;
|
||||
use Intervention\Image\Exceptions\DecoderException;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use SplFileInfo;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\InputHandler::class)]
|
||||
final class InputHandlerTest extends BaseTestCase
|
||||
{
|
||||
public function testHandleEmptyString(): void
|
||||
{
|
||||
$handler = new InputHandler();
|
||||
$this->expectException(DecoderException::class);
|
||||
$handler->handle('');
|
||||
}
|
||||
|
||||
public function testHandleBinaryImage(): void
|
||||
{
|
||||
$handler = new InputHandler();
|
||||
$input = file_get_contents($this->getTestImagePath('animation.gif'));
|
||||
$result = $handler->handle($input);
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
}
|
||||
|
||||
public function testHandleSplFileInfo(): void
|
||||
{
|
||||
$handler = new InputHandler();
|
||||
$input = new SplFileInfo($this->getTestImagePath('test.jpg'));
|
||||
$result = $handler->handle($input);
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
}
|
||||
|
||||
public function testHandleFilePathImage(): void
|
||||
{
|
||||
$handler = new InputHandler();
|
||||
$input = $this->getTestImagePath('animation.gif');
|
||||
$result = $handler->handle($input);
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
}
|
||||
|
||||
public function testHandleBase64Image(): void
|
||||
{
|
||||
$handler = new InputHandler();
|
||||
$input = base64_encode(file_get_contents($this->getTestImagePath('animation.gif')));
|
||||
$result = $handler->handle($input);
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
}
|
||||
|
||||
public function testHandleDataUriImage(): void
|
||||
{
|
||||
$handler = new InputHandler();
|
||||
$input = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACN' .
|
||||
'byblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==';
|
||||
$result = $handler->handle($input);
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
}
|
||||
|
||||
public function testHandleHexColor(): void
|
||||
{
|
||||
$handler = new InputHandler();
|
||||
$input = 'ccff33';
|
||||
$result = $handler->handle($input);
|
||||
$this->assertInstanceOf(RgbColor::class, $result);
|
||||
$this->assertEquals([204, 255, 51, 255], $result->toArray());
|
||||
|
||||
$handler = new InputHandler();
|
||||
$input = 'cf3';
|
||||
$result = $handler->handle($input);
|
||||
$this->assertInstanceOf(RgbColor::class, $result);
|
||||
$this->assertEquals([204, 255, 51, 255], $result->toArray());
|
||||
|
||||
$handler = new InputHandler();
|
||||
$input = '#123456';
|
||||
$result = $handler->handle($input);
|
||||
$this->assertInstanceOf(RgbColor::class, $result);
|
||||
$this->assertEquals([18, 52, 86, 255], $result->toArray());
|
||||
|
||||
$handler = new InputHandler();
|
||||
$input = '#333';
|
||||
$result = $handler->handle($input);
|
||||
$this->assertInstanceOf(RgbColor::class, $result);
|
||||
$this->assertEquals([51, 51, 51, 255], $result->toArray());
|
||||
|
||||
$handler = new InputHandler();
|
||||
$input = '#3333';
|
||||
$result = $handler->handle($input);
|
||||
$this->assertInstanceOf(RgbColor::class, $result);
|
||||
$this->assertEquals([51, 51, 51, 51], $result->toArray());
|
||||
|
||||
$handler = new InputHandler();
|
||||
$input = '#33333333';
|
||||
$result = $handler->handle($input);
|
||||
$this->assertInstanceOf(RgbColor::class, $result);
|
||||
$this->assertEquals([51, 51, 51, 51], $result->toArray());
|
||||
}
|
||||
|
||||
public function testHandleRgbString(): void
|
||||
{
|
||||
$handler = new InputHandler();
|
||||
$result = $handler->handle('rgb(10, 20, 30)');
|
||||
$this->assertInstanceOf(RgbColor::class, $result);
|
||||
$this->assertEquals([10, 20, 30, 255], $result->toArray());
|
||||
|
||||
$handler = new InputHandler();
|
||||
$result = $handler->handle('rgba(10, 20, 30, 1.0)');
|
||||
$this->assertInstanceOf(RgbColor::class, $result);
|
||||
$this->assertEquals([10, 20, 30, 255], $result->toArray());
|
||||
}
|
||||
|
||||
public function testHandleCmykString(): void
|
||||
{
|
||||
$handler = new InputHandler();
|
||||
$result = $handler->handle('cmyk(10, 20, 30, 40)');
|
||||
$this->assertInstanceOf(CmykColor::class, $result);
|
||||
$this->assertEquals([10, 20, 30, 40], $result->toArray());
|
||||
}
|
||||
|
||||
public function testHandleHsvString(): void
|
||||
{
|
||||
$handler = new InputHandler();
|
||||
$result = $handler->handle('hsv(10, 20, 30)');
|
||||
$this->assertInstanceOf(HsvColor::class, $result);
|
||||
$this->assertEquals([10, 20, 30], $result->toArray());
|
||||
}
|
||||
|
||||
public function testHandleTransparent(): void
|
||||
{
|
||||
$handler = new InputHandler();
|
||||
$input = 'transparent';
|
||||
$result = $handler->handle($input);
|
||||
$this->assertInstanceOf(RgbColor::class, $result);
|
||||
$this->assertEquals([255, 255, 255, 0], $result->toArray());
|
||||
}
|
||||
}
|
27
tests/Unit/Drivers/Imagick/Modifiers/BlurModifierTest.php
Normal file
27
tests/Unit/Drivers/Imagick/Modifiers/BlurModifierTest.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?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\BlurModifier;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\BlurModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\BlurModifier::class)]
|
||||
final class BlurModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testColorChange(): void
|
||||
{
|
||||
$image = $this->readTestImage('trim.png');
|
||||
$this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex());
|
||||
$image->modify(new BlurModifier(30));
|
||||
$this->assertEquals('42acb2', $image->pickColor(14, 14)->toHex());
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
<?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\BrightnessModifier;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\BrightnessModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\BrightnessModifier::class)]
|
||||
final class BrightnessModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testApply(): void
|
||||
{
|
||||
$image = $this->readTestImage('trim.png');
|
||||
$this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex());
|
||||
$image->modify(new BrightnessModifier(30));
|
||||
$this->assertEquals('39c9ff', $image->pickColor(14, 14)->toHex());
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
<?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\ColorizeModifier;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\ColorizeModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\ColorizeModifier::class)]
|
||||
final class ColorizeModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testModify(): void
|
||||
{
|
||||
$image = $this->readTestImage('tile.png');
|
||||
$image = $image->modify(new ColorizeModifier(100, -100, -100));
|
||||
$this->assertColor(251, 0, 0, 255, $image->pickColor(5, 5));
|
||||
$this->assertColor(239, 0, 0, 255, $image->pickColor(15, 15));
|
||||
}
|
||||
}
|
37
tests/Unit/Drivers/Imagick/Modifiers/ContainModifierTest.php
Normal file
37
tests/Unit/Drivers/Imagick/Modifiers/ContainModifierTest.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?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\ContainModifier;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\ContainModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\ContainModifier::class)]
|
||||
final class ContainModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testModify(): void
|
||||
{
|
||||
$image = $this->readTestImage('blocks.png');
|
||||
$this->assertEquals(640, $image->width());
|
||||
$this->assertEquals(480, $image->height());
|
||||
$result = $image->modify(new ContainModifier(200, 100, 'ff0'));
|
||||
$this->assertEquals(200, $image->width());
|
||||
$this->assertEquals(100, $image->height());
|
||||
$this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0));
|
||||
$this->assertColor(0, 0, 0, 0, $image->pickColor(140, 10));
|
||||
$this->assertColor(255, 255, 0, 255, $image->pickColor(175, 10));
|
||||
$this->assertEquals(200, $result->width());
|
||||
$this->assertEquals(100, $result->height());
|
||||
$this->assertColor(255, 255, 0, 255, $result->pickColor(0, 0));
|
||||
$this->assertColor(0, 0, 0, 0, $result->pickColor(140, 10));
|
||||
$this->assertColor(255, 255, 0, 255, $result->pickColor(175, 10));
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
<?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\ContrastModifier;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\ContrastModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\ContrastModifier::class)]
|
||||
final class ContrastModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testApply(): void
|
||||
{
|
||||
$image = $this->readTestImage('trim.png');
|
||||
$this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex());
|
||||
$image->modify(new ContrastModifier(30));
|
||||
$this->assertEquals('00fcff', $image->pickColor(14, 14)->toHex());
|
||||
}
|
||||
}
|
33
tests/Unit/Drivers/Imagick/Modifiers/CoverModifierTest.php
Normal file
33
tests/Unit/Drivers/Imagick/Modifiers/CoverModifierTest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?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\CoverModifier;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\CoverModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\CoverModifier::class)]
|
||||
final class CoverModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testModify(): void
|
||||
{
|
||||
$image = $this->readTestImage('blocks.png');
|
||||
$this->assertEquals(640, $image->width());
|
||||
$this->assertEquals(480, $image->height());
|
||||
$image->modify(new CoverModifier(100, 100, 'center'));
|
||||
$this->assertEquals(100, $image->width());
|
||||
$this->assertEquals(100, $image->height());
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(90, 90));
|
||||
$this->assertColor(0, 255, 0, 255, $image->pickColor(65, 70));
|
||||
$this->assertColor(0, 0, 255, 255, $image->pickColor(70, 52));
|
||||
$this->assertTransparency($image->pickColor(90, 30));
|
||||
}
|
||||
}
|
42
tests/Unit/Drivers/Imagick/Modifiers/CropModifierTest.php
Normal file
42
tests/Unit/Drivers/Imagick/Modifiers/CropModifierTest.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\CropModifier;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\CropModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\CropModifier::class)]
|
||||
final class CropModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testModify(): void
|
||||
{
|
||||
$image = $this->readTestImage('blocks.png');
|
||||
$image = $image->modify(new CropModifier(200, 200, 0, 0, 'ffffff', 'bottom-right'));
|
||||
$this->assertEquals(200, $image->width());
|
||||
$this->assertEquals(200, $image->height());
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(5, 5));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(100, 100));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(190, 190));
|
||||
}
|
||||
|
||||
public function testModifyExtend(): void
|
||||
{
|
||||
$image = $this->readTestImage('blocks.png');
|
||||
$image = $image->modify(new CropModifier(800, 100, -10, -10, 'ff0000', 'top-left'));
|
||||
$this->assertEquals(800, $image->width());
|
||||
$this->assertEquals(100, $image->height());
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(9, 9));
|
||||
$this->assertColor(0, 0, 255, 255, $image->pickColor(16, 16));
|
||||
$this->assertColor(0, 0, 255, 255, $image->pickColor(445, 16));
|
||||
$this->assertTransparency($image->pickColor(460, 16));
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
<?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\DrawEllipseModifier;
|
||||
use Intervention\Image\Geometry\Ellipse;
|
||||
use Intervention\Image\Geometry\Point;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\DrawEllipseModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\DrawEllipseModifier::class)]
|
||||
final class DrawEllipseModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testApply(): void
|
||||
{
|
||||
$image = $this->readTestImage('trim.png');
|
||||
$this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex());
|
||||
$drawable = new Ellipse(10, 10, new Point(14, 14));
|
||||
$drawable->setBackgroundColor('b53717');
|
||||
$image->modify(new DrawEllipseModifier($drawable));
|
||||
$this->assertEquals('b53717', $image->pickColor(14, 14)->toHex());
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
<?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\DrawLineModifier;
|
||||
use Intervention\Image\Geometry\Line;
|
||||
use Intervention\Image\Geometry\Point;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\DrawLineModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\DrawLineModifier::class)]
|
||||
final class DrawLineModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testApply(): void
|
||||
{
|
||||
$image = $this->readTestImage('trim.png');
|
||||
$this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex());
|
||||
$line = new Line(new Point(0, 0), new Point(10, 0), 4);
|
||||
$line->setBackgroundColor('b53517');
|
||||
$image->modify(new DrawLineModifier($line));
|
||||
$this->assertEquals('b53517', $image->pickColor(0, 0)->toHex());
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
<?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\DrawPixelModifier;
|
||||
use Intervention\Image\Geometry\Point;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\DrawPixelModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\DrawPixelModifier::class)]
|
||||
final class DrawPixelModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testApply(): void
|
||||
{
|
||||
$image = $this->readTestImage('trim.png');
|
||||
$this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex());
|
||||
$image->modify(new DrawPixelModifier(new Point(14, 14), 'ffffff'));
|
||||
$this->assertEquals('ffffff', $image->pickColor(14, 14)->toHex());
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
<?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\DrawPolygonModifier;
|
||||
use Intervention\Image\Geometry\Point;
|
||||
use Intervention\Image\Geometry\Polygon;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\DrawPolygonModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\DrawPolygonModifier::class)]
|
||||
final class DrawPolygonModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testApply(): void
|
||||
{
|
||||
$image = $this->readTestImage('trim.png');
|
||||
$this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex());
|
||||
$drawable = new Polygon([new Point(0, 0), new Point(15, 15), new Point(20, 20)]);
|
||||
$drawable->setBackgroundColor('b53717');
|
||||
$image->modify(new DrawPolygonModifier($drawable));
|
||||
$this->assertEquals('b53717', $image->pickColor(14, 14)->toHex());
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
<?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\DrawRectangleModifier;
|
||||
use Intervention\Image\Geometry\Point;
|
||||
use Intervention\Image\Geometry\Rectangle;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\DrawRectangleModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\DrawRectangleModifier::class)]
|
||||
final class DrawRectangleModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testApply(): void
|
||||
{
|
||||
$image = $this->readTestImage('trim.png');
|
||||
$this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex());
|
||||
$rectangle = new Rectangle(300, 200, new Point(14, 14));
|
||||
$rectangle->setBackgroundColor('ffffff');
|
||||
$image->modify(new DrawRectangleModifier($rectangle));
|
||||
$this->assertEquals('ffffff', $image->pickColor(14, 14)->toHex());
|
||||
}
|
||||
}
|
41
tests/Unit/Drivers/Imagick/Modifiers/FillModifierTest.php
Normal file
41
tests/Unit/Drivers/Imagick/Modifiers/FillModifierTest.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?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\Colors\Rgb\Color;
|
||||
use Intervention\Image\Modifiers\FillModifier;
|
||||
use Intervention\Image\Geometry\Point;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\FillModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\FillModifier::class)]
|
||||
final class FillModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testFloodFillColor(): void
|
||||
{
|
||||
$image = $this->readTestImage('blocks.png');
|
||||
$this->assertEquals('0000ff', $image->pickColor(420, 270)->toHex());
|
||||
$this->assertEquals('ff0000', $image->pickColor(540, 400)->toHex());
|
||||
$image->modify(new FillModifier(new Color(204, 204, 204), new Point(540, 400)));
|
||||
$this->assertEquals('0000ff', $image->pickColor(420, 270)->toHex());
|
||||
$this->assertEquals('cccccc', $image->pickColor(540, 400)->toHex());
|
||||
}
|
||||
|
||||
public function testFillAllColor(): void
|
||||
{
|
||||
$image = $this->readTestImage('blocks.png');
|
||||
$this->assertEquals('0000ff', $image->pickColor(420, 270)->toHex());
|
||||
$this->assertEquals('ff0000', $image->pickColor(540, 400)->toHex());
|
||||
$image->modify(new FillModifier(new Color(204, 204, 204)));
|
||||
$this->assertEquals('cccccc', $image->pickColor(420, 270)->toHex());
|
||||
$this->assertEquals('cccccc', $image->pickColor(540, 400)->toHex());
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
<?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\FlipModifier;
|
||||
use Intervention\Image\Modifiers\FlopModifier;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\FlipModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\FlopModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\FlipModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\FlopModifier::class)]
|
||||
final class FlipFlopModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testFlipImage(): void
|
||||
{
|
||||
$image = $this->readTestImage('tile.png');
|
||||
$this->assertEquals('b4e000', $image->pickColor(0, 0)->toHex());
|
||||
$image->modify(new FlipModifier());
|
||||
$this->assertEquals('00000000', $image->pickColor(0, 0)->toHex());
|
||||
}
|
||||
|
||||
public function testFlopImage(): void
|
||||
{
|
||||
$image = $this->readTestImage('tile.png');
|
||||
$this->assertEquals('b4e000', $image->pickColor(0, 0)->toHex());
|
||||
$image->modify(new FlopModifier());
|
||||
$this->assertEquals('00000000', $image->pickColor(0, 0)->toHex());
|
||||
}
|
||||
}
|
27
tests/Unit/Drivers/Imagick/Modifiers/GammaModifierTest.php
Normal file
27
tests/Unit/Drivers/Imagick/Modifiers/GammaModifierTest.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?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\GammaModifier;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\GammaModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\GammaModifier::class)]
|
||||
final class GammaModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testModifier(): void
|
||||
{
|
||||
$image = $this->readTestImage('trim.png');
|
||||
$this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex());
|
||||
$image->modify(new GammaModifier(2.1));
|
||||
$this->assertEquals('00d5f8', $image->pickColor(0, 0)->toHex());
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
<?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\GreyscaleModifier;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\GreyscaleModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\GreyscaleModifier::class)]
|
||||
final class GreyscaleModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testColorChange(): void
|
||||
{
|
||||
$image = $this->readTestImage('trim.png');
|
||||
$this->assertFalse($image->pickColor(0, 0)->isGreyscale());
|
||||
$image->modify(new GreyscaleModifier());
|
||||
$this->assertTrue($image->pickColor(0, 0)->isGreyscale());
|
||||
}
|
||||
}
|
29
tests/Unit/Drivers/Imagick/Modifiers/InvertModifierTest.php
Normal file
29
tests/Unit/Drivers/Imagick/Modifiers/InvertModifierTest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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\InvertModifier;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\InvertModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\InvertModifier::class)]
|
||||
final class InvertModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testApply(): void
|
||||
{
|
||||
$image = $this->readTestImage('trim.png');
|
||||
$this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex());
|
||||
$this->assertEquals('ffa601', $image->pickColor(25, 25)->toHex());
|
||||
$image->modify(new InvertModifier());
|
||||
$this->assertEquals('ff510f', $image->pickColor(0, 0)->toHex());
|
||||
$this->assertEquals('0059fe', $image->pickColor(25, 25)->toHex());
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
<?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\PixelateModifier;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\PixelateModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\PixelateModifier::class)]
|
||||
final class PixelateModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testModify(): void
|
||||
{
|
||||
$image = $this->readTestImage('trim.png');
|
||||
$this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex());
|
||||
$this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex());
|
||||
$image->modify(new PixelateModifier(10));
|
||||
|
||||
list($r, $g, $b) = $image->pickColor(0, 0)->toArray();
|
||||
$this->assertEquals(0, $r);
|
||||
$this->assertEquals(174, $g);
|
||||
$this->assertEquals(240, $b);
|
||||
|
||||
list($r, $g, $b) = $image->pickColor(14, 14)->toArray();
|
||||
$this->assertEquals(107, $r);
|
||||
$this->assertEquals(171, $g);
|
||||
$this->assertEquals(140, $b);
|
||||
}
|
||||
}
|
35
tests/Unit/Drivers/Imagick/Modifiers/PlaceModifierTest.php
Normal file
35
tests/Unit/Drivers/Imagick/Modifiers/PlaceModifierTest.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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\PlaceModifier;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\BlurModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\PlaceModifier::class)]
|
||||
final class PlaceModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testColorChange(): void
|
||||
{
|
||||
$image = $this->readTestImage('test.jpg');
|
||||
$this->assertEquals('febc44', $image->pickColor(300, 25)->toHex());
|
||||
$image->modify(new PlaceModifier($this->getTestImagePath('circle.png'), 'top-right', 0, 0));
|
||||
$this->assertEquals('33260e', $image->pickColor(300, 25)->toHex());
|
||||
}
|
||||
|
||||
public function testColorChangeOpacity(): void
|
||||
{
|
||||
$image = $this->readTestImage('test.jpg');
|
||||
$this->assertEquals('febc44', $image->pickColor(300, 25)->toHex());
|
||||
$image->modify(new PlaceModifier($this->getTestImagePath('circle.png'), 'top-right', 0, 0, 50));
|
||||
$this->assertEquals('987129', $image->pickColor(300, 25)->toHex());
|
||||
}
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
<?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\Exceptions\InputException;
|
||||
use Intervention\Image\Modifiers\QuantizeColorsModifier;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\QuantizeColorsModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\QuantizeColorsModifier::class)]
|
||||
final class QuantizeColorsModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testColorChange(): void
|
||||
{
|
||||
$image = $this->readTestImage('gradient.bmp');
|
||||
$this->assertEquals(15, $image->core()->native()->getImageColors());
|
||||
$image->modify(new QuantizeColorsModifier(4));
|
||||
$this->assertEquals(4, $image->core()->native()->getImageColors());
|
||||
}
|
||||
|
||||
public function testNoColorReduction(): void
|
||||
{
|
||||
$image = $this->readTestImage('gradient.bmp');
|
||||
$this->assertEquals(15, $image->core()->native()->getImageColors());
|
||||
$image->modify(new QuantizeColorsModifier(150));
|
||||
$this->assertEquals(15, $image->core()->native()->getImageColors());
|
||||
}
|
||||
|
||||
public function testInvalidColorInput(): void
|
||||
{
|
||||
$image = $this->readTestImage('gradient.bmp');
|
||||
$this->expectException(InputException::class);
|
||||
$image->modify(new QuantizeColorsModifier(0));
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
<?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\Exceptions\InputException;
|
||||
use Intervention\Image\Modifiers\RemoveAnimationModifier;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\RemoveAnimationModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\RemoveAnimationModifier::class)]
|
||||
final class RemoveAnimationModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testApply(): void
|
||||
{
|
||||
$image = $this->readTestImage('animation.gif');
|
||||
$this->assertEquals(8, count($image));
|
||||
$result = $image->modify(new RemoveAnimationModifier(2));
|
||||
$this->assertEquals(1, count($image));
|
||||
$this->assertEquals(1, count($result));
|
||||
}
|
||||
|
||||
public function testApplyPercent(): void
|
||||
{
|
||||
$image = $this->readTestImage('animation.gif');
|
||||
$this->assertEquals(8, count($image));
|
||||
$result = $image->modify(new RemoveAnimationModifier('20%'));
|
||||
$this->assertEquals(1, count($image));
|
||||
$this->assertEquals(1, count($result));
|
||||
}
|
||||
|
||||
public function testApplyInvalid(): void
|
||||
{
|
||||
$image = $this->readTestImage('animation.gif');
|
||||
$this->expectException(InputException::class);
|
||||
$image->modify(new RemoveAnimationModifier('test'));
|
||||
}
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
<?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\ResizeCanvasModifier;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\ResizeCanvasModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\ResizeCanvasModifier::class)]
|
||||
final class ResizeCanvasModifierTest extends BaseTestCase
|
||||
{
|
||||
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());
|
||||
$this->assertEquals(16, $image->height());
|
||||
$image->modify(new ResizeCanvasModifier(18, 18, 'ff0', 'center'));
|
||||
$this->assertEquals(18, $image->width());
|
||||
$this->assertEquals(18, $image->height());
|
||||
$this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0));
|
||||
$this->assertColor(180, 224, 0, 255, $image->pickColor(1, 1));
|
||||
$this->assertColor(180, 224, 0, 255, $image->pickColor(2, 2));
|
||||
$this->assertColor(255, 255, 0, 255, $image->pickColor(17, 17));
|
||||
$this->assertTransparency($image->pickColor(12, 1));
|
||||
}
|
||||
|
||||
public function testModifyEdge(): void
|
||||
{
|
||||
$image = $this->createTestImage(1, 1);
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(0, 0));
|
||||
$image->modify(new ResizeCanvasModifier(null, 2, 'ff0', 'bottom'));
|
||||
$this->assertEquals(1, $image->width());
|
||||
$this->assertEquals(2, $image->height());
|
||||
$this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0));
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(0, 1));
|
||||
}
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
<?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\ResizeCanvasRelativeModifier;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\ResizeCanvasRelativeModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\ResizeCanvasRelativeModifier::class)]
|
||||
final class ResizeCanvasRelativeModifierTest extends BaseTestCase
|
||||
{
|
||||
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());
|
||||
$this->assertEquals(16, $image->height());
|
||||
$image->modify(new ResizeCanvasRelativeModifier(2, 2, 'ff0', 'center'));
|
||||
$this->assertEquals(18, $image->width());
|
||||
$this->assertEquals(18, $image->height());
|
||||
$this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0));
|
||||
$this->assertColor(180, 224, 0, 255, $image->pickColor(1, 1));
|
||||
$this->assertColor(180, 224, 0, 255, $image->pickColor(2, 2));
|
||||
$this->assertColor(255, 255, 0, 255, $image->pickColor(17, 17));
|
||||
$this->assertTransparency($image->pickColor(12, 1));
|
||||
}
|
||||
}
|
30
tests/Unit/Drivers/Imagick/Modifiers/ResizeModifierTest.php
Normal file
30
tests/Unit/Drivers/Imagick/Modifiers/ResizeModifierTest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?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\ResizeModifier;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\ResizeModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\ResizeModifier::class)]
|
||||
final class ResizeModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testModify(): void
|
||||
{
|
||||
$image = $this->readTestImage('blocks.png');
|
||||
$this->assertEquals(640, $image->width());
|
||||
$this->assertEquals(480, $image->height());
|
||||
$image->modify(new ResizeModifier(200, 100));
|
||||
$this->assertEquals(200, $image->width());
|
||||
$this->assertEquals(100, $image->height());
|
||||
$this->assertColor(255, 0, 0, 255, $image->pickColor(150, 70));
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
<?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\ResolutionModifier;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\ResolutionModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\ResolutionModifier::class)]
|
||||
final class ResolutionModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testResolutionChange(): void
|
||||
{
|
||||
$image = $this->readTestImage('test.jpg');
|
||||
$this->assertEquals(72.0, $image->resolution()->x());
|
||||
$this->assertEquals(72.0, $image->resolution()->y());
|
||||
$image->modify(new ResolutionModifier(1, 2));
|
||||
$this->assertEquals(1.0, $image->resolution()->x());
|
||||
$this->assertEquals(2.0, $image->resolution()->y());
|
||||
}
|
||||
}
|
29
tests/Unit/Drivers/Imagick/Modifiers/RotateModifierTest.php
Normal file
29
tests/Unit/Drivers/Imagick/Modifiers/RotateModifierTest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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\RotateModifier;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\RotateModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\RotateModifier::class)]
|
||||
final class RotateModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testRotate(): void
|
||||
{
|
||||
$image = $this->readTestImage('test.jpg');
|
||||
$this->assertEquals(320, $image->width());
|
||||
$this->assertEquals(240, $image->height());
|
||||
$image->modify(new RotateModifier(90, 'fff'));
|
||||
$this->assertEquals(240, $image->width());
|
||||
$this->assertEquals(320, $image->height());
|
||||
}
|
||||
}
|
27
tests/Unit/Drivers/Imagick/Modifiers/SharpenModifierTest.php
Normal file
27
tests/Unit/Drivers/Imagick/Modifiers/SharpenModifierTest.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?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\SharpenModifier;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(\Intervention\Image\Modifiers\SharpenModifier::class)]
|
||||
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\SharpenModifier::class)]
|
||||
final class SharpenModifierTest extends BaseTestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testModify(): void
|
||||
{
|
||||
$image = $this->readTestImage('trim.png');
|
||||
$this->assertEquals('60ab96', $image->pickColor(15, 14)->toHex());
|
||||
$image->modify(new SharpenModifier(10));
|
||||
$this->assertEquals('4faca6', $image->pickColor(15, 14)->toHex());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user