Skip to content

Commit

Permalink
added heic support
Browse files Browse the repository at this point in the history
  • Loading branch information
boryn committed Sep 30, 2023
1 parent e5251db commit 46dcd5a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Conversions/ImageGenerators/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public function supportedExtensions(): Collection
$extensions = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'avif'];
if (config('media-library.image_driver') === 'imagick') {
$extensions[] = 'tiff';
$extensions[] = 'heic';
$extensions[] = 'heif';
}

return collect($extensions);
Expand All @@ -32,6 +34,8 @@ public function supportedMimeTypes(): Collection
$mimeTypes = ['image/jpeg', 'image/gif', 'image/png', 'image/webp', 'image/avif'];
if (config('media-library.image_driver') === 'imagick') {
$mimeTypes[] = 'image/tiff';
$mimeTypes[] = 'image/heic';
$mimeTypes[] = 'image/heif';
}

return collect($mimeTypes);
Expand Down
19 changes: 19 additions & 0 deletions tests/Conversions/ImageGenerators/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,22 @@ function () {
expect($media->getPath())->toEqual($imageFile);
}
)->skip(! extension_loaded('imagick'), 'The imagick extension is not available.');

it(
'can convert a heic image',
function () {
//heic format requires imagick
config(['media-library.image_driver' => 'imagick']);

$imageGenerator = new Image();

$media = $this->testModelWithoutMediaConversions->addMedia($this->getTestHeic())->toMediaCollection();

expect($imageGenerator->canConvert($media))->toBeTrue();

$imageFile = $imageGenerator->convert($media->getPath());

expect(mime_content_type($imageFile))->toEqual('image/heic');
expect($media->getPath())->toEqual($imageFile);
}
)->skip(! extension_loaded('imagick'), 'The imagick extension is not available.');
5 changes: 5 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ public function getTestAvif(): string
return $this->getTestFilesDirectory('test.avif');
}

public function getTestHeic(): string
{
return $this->getTestFilesDirectory('test.heic');
}

public function getTestMp4(): string
{
return $this->getTestFilesDirectory('test.mp4');
Expand Down
Binary file added tests/TestSupport/testfiles/test.heic
Binary file not shown.

0 comments on commit 46dcd5a

Please sign in to comment.