From 6e104b6594d64bca359e0b24533d4e9c38844eaa Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Wed, 10 Apr 2024 15:17:36 +0200 Subject: [PATCH] Add ability to read Imagick or GDImage directly (#1329) --- src/Decoders/NativeObjectDecoder.php | 11 +++++++++++ src/Drivers/Gd/Decoders/BinaryImageDecoder.php | 2 +- src/Drivers/Gd/Decoders/FilePathImageDecoder.php | 2 +- .../{GdImageDecoder.php => NativeObjectDecoder.php} | 7 ++++++- src/Drivers/Gd/InputHandler.php | 2 ++ src/Drivers/Imagick/Decoders/BinaryImageDecoder.php | 2 +- src/Drivers/Imagick/Decoders/FilePathImageDecoder.php | 2 +- ...magickImageDecoder.php => NativeObjectDecoder.php} | 2 +- src/Drivers/Imagick/InputHandler.php | 2 ++ tests/Unit/Drivers/Gd/InputHandlerTest.php | 7 +++++++ tests/Unit/Drivers/Imagick/InputHandlerTest.php | 11 +++++++++++ 11 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 src/Decoders/NativeObjectDecoder.php rename src/Drivers/Gd/Decoders/{GdImageDecoder.php => NativeObjectDecoder.php} (88%) rename src/Drivers/Imagick/Decoders/{ImagickImageDecoder.php => NativeObjectDecoder.php} (96%) diff --git a/src/Decoders/NativeObjectDecoder.php b/src/Decoders/NativeObjectDecoder.php new file mode 100644 index 00000000..ff83cd95 --- /dev/null +++ b/src/Decoders/NativeObjectDecoder.php @@ -0,0 +1,11 @@ +assertInstanceOf(Image::class, $result); } + public function testHandleGdImage(): void + { + $handler = new InputHandler(); + $result = $handler->handle(imagecreatetruecolor(3, 2)); + $this->assertInstanceOf(Image::class, $result); + } + public function testHandleSplFileInfo(): void { $handler = new InputHandler(); diff --git a/tests/Unit/Drivers/Imagick/InputHandlerTest.php b/tests/Unit/Drivers/Imagick/InputHandlerTest.php index 16449d4e..1b4fbf39 100644 --- a/tests/Unit/Drivers/Imagick/InputHandlerTest.php +++ b/tests/Unit/Drivers/Imagick/InputHandlerTest.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick; +use Imagick; +use ImagickPixel; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Colors\Cmyk\Color as CmykColor; @@ -34,6 +36,15 @@ final class InputHandlerTest extends BaseTestCase $this->assertInstanceOf(Image::class, $result); } + public function testHandleImagick(): void + { + $imagick = new Imagick(); + $imagick->newImage(3, 2, new ImagickPixel('rgba(255, 255, 255, 255)'), 'png'); + $handler = new InputHandler(); + $result = $handler->handle($imagick); + $this->assertInstanceOf(Image::class, $result); + } + public function testHandleSplFileInfo(): void { $handler = new InputHandler();