From 31779d02636a315ec3b53225308ddb95083539d4 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sun, 11 Aug 2024 11:43:54 +0200 Subject: [PATCH] Add ability to read instances of EncodedImaged::class (#1386) * Implement EncodedImageObjectDecoder::class * Add tests for EncodedImageObjectDecoder::class --- src/Decoders/EncodedImageObjectDecoder.php | 11 +++++++ .../Gd/Decoders/EncodedImageObjectDecoder.php | 27 ++++++++++++++++ .../Decoders/EncodedImageObjectDecoder.php | 27 ++++++++++++++++ src/InputHandler.php | 2 ++ .../EncodedImageObjectDecoderTest.php | 32 +++++++++++++++++++ .../EncodedImageObjectDecoderTest.php | 32 +++++++++++++++++++ 6 files changed, 131 insertions(+) create mode 100644 src/Decoders/EncodedImageObjectDecoder.php create mode 100644 src/Drivers/Gd/Decoders/EncodedImageObjectDecoder.php create mode 100644 src/Drivers/Imagick/Decoders/EncodedImageObjectDecoder.php create mode 100644 tests/Unit/Drivers/Gd/Decoders/EncodedImageObjectDecoderTest.php create mode 100644 tests/Unit/Drivers/Imagick/Decoders/EncodedImageObjectDecoderTest.php diff --git a/src/Decoders/EncodedImageObjectDecoder.php b/src/Decoders/EncodedImageObjectDecoder.php new file mode 100644 index 00000000..daddff2d --- /dev/null +++ b/src/Decoders/EncodedImageObjectDecoder.php @@ -0,0 +1,11 @@ +toString()); + } +} diff --git a/src/Drivers/Imagick/Decoders/EncodedImageObjectDecoder.php b/src/Drivers/Imagick/Decoders/EncodedImageObjectDecoder.php new file mode 100644 index 00000000..2348a6b7 --- /dev/null +++ b/src/Drivers/Imagick/Decoders/EncodedImageObjectDecoder.php @@ -0,0 +1,27 @@ +toString()); + } +} diff --git a/src/InputHandler.php b/src/InputHandler.php index 2772ec45..a0720d13 100644 --- a/src/InputHandler.php +++ b/src/InputHandler.php @@ -15,6 +15,7 @@ use Intervention\Image\Decoders\BinaryImageDecoder; use Intervention\Image\Decoders\ColorObjectDecoder; use Intervention\Image\Decoders\DataUriImageDecoder; +use Intervention\Image\Decoders\EncodedImageObjectDecoder; use Intervention\Image\Decoders\FilePathImageDecoder; use Intervention\Image\Decoders\FilePointerImageDecoder; use Intervention\Image\Decoders\ImageObjectDecoder; @@ -53,6 +54,7 @@ class InputHandler implements InputHandlerInterface BinaryImageDecoder::class, DataUriImageDecoder::class, Base64ImageDecoder::class, + EncodedImageObjectDecoder::class, ]; /** diff --git a/tests/Unit/Drivers/Gd/Decoders/EncodedImageObjectDecoderTest.php b/tests/Unit/Drivers/Gd/Decoders/EncodedImageObjectDecoderTest.php new file mode 100644 index 00000000..f75762f1 --- /dev/null +++ b/tests/Unit/Drivers/Gd/Decoders/EncodedImageObjectDecoderTest.php @@ -0,0 +1,32 @@ +decoder = new EncodedImageObjectDecoder(); + $this->decoder->setDriver(new Driver()); + } + + public function testDecode(): void + { + $result = $this->decoder->decode(new EncodedImage($this->getTestResourceData())); + $this->assertInstanceOf(Image::class, $result); + } +} diff --git a/tests/Unit/Drivers/Imagick/Decoders/EncodedImageObjectDecoderTest.php b/tests/Unit/Drivers/Imagick/Decoders/EncodedImageObjectDecoderTest.php new file mode 100644 index 00000000..826498d3 --- /dev/null +++ b/tests/Unit/Drivers/Imagick/Decoders/EncodedImageObjectDecoderTest.php @@ -0,0 +1,32 @@ +decoder = new EncodedImageObjectDecoder(); + $this->decoder->setDriver(new Driver()); + } + + public function testDecode(): void + { + $result = $this->decoder->decode(new EncodedImage($this->getTestResourceData())); + $this->assertInstanceOf(Image::class, $result); + } +}