Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TIFF support in v10 #2802

Merged
merged 3 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"illuminate/support": "^9.0",
"intervention/image": "^2.7",
"maennchen/zipstream-php": "^2.0",
"spatie/image": "^2.2",
"spatie/image": "^2.2.2",
"spatie/temporary-directory": "^2.0",
"symfony/console": "^6.0"
},
Expand Down
14 changes: 12 additions & 2 deletions src/Conversions/ImageGenerators/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@ public function requirementsAreInstalled(): bool

public function supportedExtensions(): Collection
{
return collect(['png', 'jpg', 'jpeg', 'gif']);
$extensions = ['png', 'jpg', 'jpeg', 'gif'];
if (config('media-library.image_driver') === 'imagick') {
$extensions[] = 'tiff';
}

return collect($extensions);
}

public function supportedMimeTypes(): Collection
{
return collect(['image/jpeg', 'image/gif', 'image/png']);
$mimeTypes = ['image/jpeg', 'image/gif', 'image/png'];
if (config('media-library.image_driver') === 'imagick') {
$mimeTypes[] = 'image/tiff';
}

return collect($mimeTypes);
}
}
19 changes: 19 additions & 0 deletions tests/Conversions/ImageGenerators/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,22 @@
expect(mime_content_type($imageFile))->toEqual('image/jpeg');
expect($media->getPath())->toEqual($imageFile);
});

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

$imageGenerator = new Image();

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

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

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

expect(mime_content_type($imageFile))->toEqual('image/tiff');
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 @@ -206,6 +206,11 @@ public function getUppercaseExtensionTestPng(): string
return $this->getTestFilesDirectory('uppercaseExtensionTest.PNG');
}

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

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