Skip to content

Commit

Permalink
Merge pull request #382 from thephpleague/3.x-heic
Browse files Browse the repository at this point in the history
Add support HEIC image format
  • Loading branch information
ADmad authored Jan 28, 2024
2 parents 3d4ea7d + 3d9933a commit 652b80b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
1 change: 1 addition & 0 deletions src/Manipulators/Encode.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public static function supportedFormats(): array
'png' => 'image/png',
'webp' => 'image/webp',
'tiff' => 'image/tiff',
'heic' => 'image/heic',
];
}

Expand Down
21 changes: 20 additions & 1 deletion tests/Manipulators/EncodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class EncodeTest extends TestCase
private $tif;
private $webp;
private $avif;
private $heic;

public function setUp(): void
{
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 652b80b

Please sign in to comment.