From 43d32ca4a8bc68d305c75d9924937f45968ba4c0 Mon Sep 17 00:00:00 2001 From: Lazizbek Ergashev Date: Mon, 24 Aug 2026 16:16:52 +0500 Subject: [PATCH 1/2] Remove JsonSerializable from EncodedImage --- src/EncodedImage.php | 15 +-------------- tests/Unit/EncodedImageTest.php | 7 +++++-- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/EncodedImage.php b/src/EncodedImage.php index d0d872770..a6459f3c5 100644 --- a/src/EncodedImage.php +++ b/src/EncodedImage.php @@ -8,10 +8,9 @@ use Intervention\Image\Exceptions\StreamException; use Intervention\Image\Interfaces\DataUriInterface; use Intervention\Image\Interfaces\EncodedImageInterface; -use JsonSerializable; use Throwable; -class EncodedImage extends File implements EncodedImageInterface, JsonSerializable +class EncodedImage extends File implements EncodedImageInterface { /** * Create new instance. @@ -74,18 +73,6 @@ public function toBase64(): string return base64_encode((string) $this); } - /** - * {@inheritdoc} - * - * @see JsonSerializable::jsonSerialize() - * - * @throws StreamException - */ - public function jsonSerialize(): mixed - { - return $this->toDataUri(); - } - /** * Show debug info for the current image. * diff --git a/tests/Unit/EncodedImageTest.php b/tests/Unit/EncodedImageTest.php index 665b6039c..d7f6ed28b 100644 --- a/tests/Unit/EncodedImageTest.php +++ b/tests/Unit/EncodedImageTest.php @@ -52,10 +52,13 @@ public function testToString(): void $this->assertEquals('foo', (string) $image); } - public function testJsonSerialze(): void + public function testNotJsonSerializable(): void { + // EncodedImage must not implement JsonSerializable, since frameworks + // like Laravel treat that as a signal to encode HTTP responses as + // JSON, overriding the correct image content type. $image = new EncodedImage('foo'); - $this->assertEquals('["data:application\/octet-stream;base64,Zm9v"]', json_encode([$image])); + $this->assertNotInstanceOf(\JsonSerializable::class, $image); } public function testMediaType(): void From 7f25da962ba359db86c29015c5dcc7c867e9b52c Mon Sep 17 00:00:00 2001 From: Lazizbek Ergashev Date: Mon, 24 Aug 2026 16:19:23 +0500 Subject: [PATCH 2/2] Tighten regression test comment and imports --- tests/Unit/EncodedImageTest.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/Unit/EncodedImageTest.php b/tests/Unit/EncodedImageTest.php index d7f6ed28b..9d981bec0 100644 --- a/tests/Unit/EncodedImageTest.php +++ b/tests/Unit/EncodedImageTest.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Tests\Unit; +use JsonSerializable; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\EncodedImage; use Intervention\Image\Tests\BaseTestCase; @@ -54,11 +55,9 @@ public function testToString(): void public function testNotJsonSerializable(): void { - // EncodedImage must not implement JsonSerializable, since frameworks - // like Laravel treat that as a signal to encode HTTP responses as - // JSON, overriding the correct image content type. + // Frameworks like Laravel force application/json responses for JsonSerializable content. $image = new EncodedImage('foo'); - $this->assertNotInstanceOf(\JsonSerializable::class, $image); + $this->assertNotInstanceOf(JsonSerializable::class, $image); } public function testMediaType(): void