From 3d9933a6b7743a4a466aef72b7d73607c521359d Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 28 Jan 2024 20:28:06 +0530 Subject: [PATCH] Add support HEIC image format --- composer.json | 2 +- src/Manipulators/Encode.php | 1 + tests/Manipulators/EncodeTest.php | 21 ++++++++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index ef25206..b99a6ec 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ ], "require": { "php": "^8.1", - "intervention/image": "^3.2", + "intervention/image": "^3.3", "league/flysystem": "^2.0|^3.0", "psr/http-message": "^1.0|^2.0" }, diff --git a/src/Manipulators/Encode.php b/src/Manipulators/Encode.php index 61a24af..f951446 100644 --- a/src/Manipulators/Encode.php +++ b/src/Manipulators/Encode.php @@ -83,6 +83,7 @@ public static function supportedFormats(): array 'png' => 'image/png', 'webp' => 'image/webp', 'tiff' => 'image/tiff', + 'heic' => 'image/heic', ]; } diff --git a/tests/Manipulators/EncodeTest.php b/tests/Manipulators/EncodeTest.php index 8b7080e..f3a5d1d 100644 --- a/tests/Manipulators/EncodeTest.php +++ b/tests/Manipulators/EncodeTest.php @@ -16,6 +16,7 @@ class EncodeTest extends TestCase private $tif; private $webp; private $avif; + private $heic; public function setUp(): void { @@ -162,14 +163,32 @@ public function testWithImagick() $this->jpg = $manager->read($manager->create(100, 100)->encode(new MediaTypeEncoder('image/jpeg'))->toFilePointer()); $this->png = $manager->read($manager->create(100, 100)->encode(new MediaTypeEncoder('image/png'))->toFilePointer()); $this->gif = $manager->read($manager->create(100, 100)->encode(new MediaTypeEncoder('image/gif'))->toFilePointer()); + $this->heic = $manager->read($manager->create(100, 100)->encode(new MediaTypeEncoder('image/heic'))->toFilePointer()); $this->tif = $manager->read($manager->create(100, 100)->encode(new MediaTypeEncoder('image/tiff'))->toFilePointer()); $this->assertSame('image/tiff', $this->getMime($this->manipulator->setParams(['fm' => 'tiff'])->run($this->jpg))); $this->assertSame('image/tiff', $this->getMime($this->manipulator->setParams(['fm' => 'tiff'])->run($this->png))); $this->assertSame('image/tiff', $this->getMime($this->manipulator->setParams(['fm' => 'tiff'])->run($this->gif))); + $this->assertSame('image/tiff', $this->getMime($this->manipulator->setParams(['fm' => 'tiff'])->run($this->heic))); } - public function getMime(ImageInterface $image) + public function testSupportedFormats() + { + $expected = [ + 'avif' => 'image/avif', + 'gif' => 'image/gif', + 'jpg' => 'image/jpeg', + 'pjpg' => 'image/jpeg', + 'png' => 'image/png', + 'webp' => 'image/webp', + 'tiff' => 'image/tiff', + 'heic' => 'image/heic', + ]; + + $this->assertSame($expected, Encode::supportedFormats()); + } + + protected function getMime(ImageInterface $image) { return $image->origin()->mediaType(); }