From ee160063f7dd455c6a536b8db1cf7277b12ecc69 Mon Sep 17 00:00:00 2001 From: Marcus Bointon Date: Sun, 20 Feb 2022 22:33:01 +0100 Subject: [PATCH 1/7] Add TIFF format constant --- src/Manipulations.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Manipulations.php b/src/Manipulations.php index 8bfaf26f..af265657 100644 --- a/src/Manipulations.php +++ b/src/Manipulations.php @@ -43,6 +43,7 @@ class Manipulations public const FORMAT_GIF = 'gif'; public const FORMAT_WEBP = 'webp'; public const FORMAT_AVIF = 'avif'; + public const FORMAT_TIFF = 'tiff'; public const FILTER_GREYSCALE = 'greyscale'; public const FILTER_SEPIA = 'sepia'; From e70aa8d4c63d11deba3d9c67763d1553fb0a22ad Mon Sep 17 00:00:00 2001 From: Marcus Bointon Date: Sun, 20 Feb 2022 22:33:48 +0100 Subject: [PATCH 2/7] Update format list to use constants, and add TIFF format if we are using imagick --- src/Image.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Image.php b/src/Image.php index 4cc57ee2..891889b5 100644 --- a/src/Image.php +++ b/src/Image.php @@ -171,7 +171,18 @@ protected function addFormatManipulation($outputPath): void return; } - $supportedFormats = ['jpg', 'pjpg', 'png', 'gif', 'webp', 'avif']; + $supportedFormats = [ + Manipulations::FORMAT_JPG, + Manipulations::FORMAT_PJPG, + Manipulations::FORMAT_PNG, + Manipulations::FORMAT_GIF, + Manipulations::FORMAT_WEBP, + Manipulations::FORMAT_AVIF, + ]; + //gd driver doesn't support TIFF + if ($this->imageDriver === 'imagick') { + $supportedFormats[] = Manipulations::FORMAT_TIFF; + } if (in_array($outputExtension, $supportedFormats)) { $this->manipulations->format($outputExtension); From ec219ac90fefeacb925892f8f86cd4adc7bef586 Mon Sep 17 00:00:00 2001 From: Marcus Bointon Date: Sun, 20 Feb 2022 22:34:12 +0100 Subject: [PATCH 3/7] Add a test for TIFF format --- tests/ImageTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/ImageTest.php b/tests/ImageTest.php index 17ae38d8..75fd47df 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -76,6 +76,14 @@ public function it_will_create_a_file_in_the_format_according_to_its_extension() $image = new Imagick($targetFile); $this->assertSame('AVIF', $image->getImageFormat()); } + + //test tiff format with imagick + if (!empty(Imagick::queryFormats('TIFF*'))) { + $targetFile = $this->tempDir->path('conversion.tiff'); + Image::load($this->getTestJpg())->useImageDriver('imagick')->save($targetFile); + $image = new Imagick($targetFile); + $this->assertSame('TIFF', $image->getImageFormat()); + } } /** @test */ From a9342b097fae60afa2815300cadeff5a1ddd5be5 Mon Sep 17 00:00:00 2001 From: Marcus Bointon Date: Sun, 20 Feb 2022 22:34:49 +0100 Subject: [PATCH 4/7] Docs --- docs/usage/saving-images.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/usage/saving-images.md b/docs/usage/saving-images.md index 6d5cc91b..4aeec646 100644 --- a/docs/usage/saving-images.md +++ b/docs/usage/saving-images.md @@ -21,7 +21,7 @@ Image::load('example.jpg') ## Saving in a different image format -To save your image as a different image format call the `format` method and pass in the desired format. Currently the following formats are supported: `FORMAT_JPG`, `FORMAT_PJPG`, `FORMAT_PNG`, `FORMAT_GIF` and `FORMAT_WEBP`. +To save your image as a different image format call the `format` method and pass in the desired format. Currently the following formats are supported: `FORMAT_JPG`, `FORMAT_PJPG`, `FORMAT_PNG`, `FORMAT_GIF`, `FORMAT_WEBP` and `FORMAT_TIFF`. ```php Image::load('example.jpg') From bce3ebcef42f95ad8358cfe15aa9f1b22cd30ac0 Mon Sep 17 00:00:00 2001 From: Marcus Bointon Date: Mon, 21 Feb 2022 09:03:31 +0100 Subject: [PATCH 5/7] Bump glide version to include TIFF support fix --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 254d2b69..2faa459a 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "ext-exif": "*", "ext-mbstring": "*", "ext-json": "*", - "league/glide": "^2.0", + "league/glide": "^2.2.2", "spatie/image-optimizer": "^1.1", "spatie/temporary-directory": "^1.0|^2.0", "symfony/process": "^3.0|^4.0|^5.0|^6.0" From ccea008b77bf81cea51d42b8f2e6f9f885fbb279 Mon Sep 17 00:00:00 2001 From: Marcus Bointon Date: Mon, 21 Feb 2022 09:03:55 +0100 Subject: [PATCH 6/7] CS --- tests/ImageTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ImageTest.php b/tests/ImageTest.php index 75fd47df..f7ba5cf3 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -78,7 +78,7 @@ public function it_will_create_a_file_in_the_format_according_to_its_extension() } //test tiff format with imagick - if (!empty(Imagick::queryFormats('TIFF*'))) { + if (! empty(Imagick::queryFormats('TIFF*'))) { $targetFile = $this->tempDir->path('conversion.tiff'); Image::load($this->getTestJpg())->useImageDriver('imagick')->save($targetFile); $image = new Imagick($targetFile); From 411397ce5c02c3a67481c8ae2da125eff848386f Mon Sep 17 00:00:00 2001 From: Marcus Bointon Date: Mon, 21 Feb 2022 09:05:08 +0100 Subject: [PATCH 7/7] The image driver may have been changed by other tests, so set it explicitly --- tests/ImageTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/ImageTest.php b/tests/ImageTest.php index f7ba5cf3..9489a8d2 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -109,6 +109,8 @@ public function the_image_driver_is_set_on_the_intervention_static_manager() { $image = Image::load($this->getTestJpg()); + $image->useImageDriver('gd'); + $this->assertSame('gd', InterventionImage::getManager()->config['driver'] ?? null); $image->useImageDriver('imagick');