diff --git a/composer.json b/composer.json index 5e551040b..c745a2d88 100644 --- a/composer.json +++ b/composer.json @@ -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" }, diff --git a/src/Conversions/ImageGenerators/Image.php b/src/Conversions/ImageGenerators/Image.php index bb6ab817a..19df8b16a 100644 --- a/src/Conversions/ImageGenerators/Image.php +++ b/src/Conversions/ImageGenerators/Image.php @@ -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); } } diff --git a/tests/Conversions/ImageGenerators/ImageTest.php b/tests/Conversions/ImageGenerators/ImageTest.php index 393f05416..656b86c27 100644 --- a/tests/Conversions/ImageGenerators/ImageTest.php +++ b/tests/Conversions/ImageGenerators/ImageTest.php @@ -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.'); diff --git a/tests/TestCase.php b/tests/TestCase.php index 0950dd3b9..3db791c94 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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'); diff --git a/tests/TestSupport/testfiles/test.tiff b/tests/TestSupport/testfiles/test.tiff new file mode 100644 index 000000000..f8182c2e1 Binary files /dev/null and b/tests/TestSupport/testfiles/test.tiff differ