From cf323d66c2b9674f45d1a11c26ce8d22f5b88515 Mon Sep 17 00:00:00 2001 From: Nicolas Beauvais Date: Thu, 21 Nov 2024 16:26:03 +0100 Subject: [PATCH 1/4] Fix SVG files loosing transparency during conversion --- src/Conversions/ImageGenerators/Svg.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Conversions/ImageGenerators/Svg.php b/src/Conversions/ImageGenerators/Svg.php index a40eb53df..881fe13ab 100644 --- a/src/Conversions/ImageGenerators/Svg.php +++ b/src/Conversions/ImageGenerators/Svg.php @@ -11,12 +11,13 @@ class Svg extends ImageGenerator { public function convert(string $file, ?Conversion $conversion = null): string { - $imageFile = pathinfo($file, PATHINFO_DIRNAME).'/'.pathinfo($file, PATHINFO_FILENAME).'.jpg'; + $imageFile = pathinfo($file, PATHINFO_DIRNAME).'/'.pathinfo($file, PATHINFO_FILENAME).'.png'; - $image = new Imagick; - $image->readImage($file); + $image = new Imagick(); $image->setBackgroundColor(new ImagickPixel('none')); - $image->setImageFormat('jpg'); + $image->readImage($file); + + $image->setImageFormat('png32'); file_put_contents($imageFile, $image); From 74a1acd48a0278c2371349cb59cbbfe648ec5241 Mon Sep 17 00:00:00 2001 From: Nicolas Beauvais Date: Thu, 21 Nov 2024 17:05:28 +0100 Subject: [PATCH 2/4] Update SvgTest to allow png format --- tests/Conversions/ImageGenerators/SvgTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Conversions/ImageGenerators/SvgTest.php b/tests/Conversions/ImageGenerators/SvgTest.php index fb6eebbae..46dd43524 100644 --- a/tests/Conversions/ImageGenerators/SvgTest.php +++ b/tests/Conversions/ImageGenerators/SvgTest.php @@ -17,5 +17,5 @@ $imageFile = $imageGenerator->convert($media->getPath()); - expect(mime_content_type($imageFile))->toEqual('image/jpeg'); + expect(mime_content_type($imageFile))->toEqual('image/png'); })->skipWhenRunningLocally(); From b94cb95f53a42218ecdb84d28fa402aa8149c2e6 Mon Sep 17 00:00:00 2001 From: Nicolas Beauvais Date: Thu, 21 Nov 2024 17:06:34 +0100 Subject: [PATCH 3/4] Test that SVG conversion maintain transparency --- tests/Conversions/ImageGenerators/SvgTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Conversions/ImageGenerators/SvgTest.php b/tests/Conversions/ImageGenerators/SvgTest.php index 46dd43524..7ce417fac 100644 --- a/tests/Conversions/ImageGenerators/SvgTest.php +++ b/tests/Conversions/ImageGenerators/SvgTest.php @@ -18,4 +18,6 @@ $imageFile = $imageGenerator->convert($media->getPath()); expect(mime_content_type($imageFile))->toEqual('image/png'); + + expect((new Imagick($imageFile))->getImageAlphaChannel())->toBeTrue(); })->skipWhenRunningLocally(); From 8dbb2518572539b13aa4268a0c535a61fcb750bd Mon Sep 17 00:00:00 2001 From: Nicolas Beauvais Date: Thu, 21 Nov 2024 17:07:05 +0100 Subject: [PATCH 4/4] Allow SvgTest to be run locally --- tests/Conversions/ImageGenerators/SvgTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Conversions/ImageGenerators/SvgTest.php b/tests/Conversions/ImageGenerators/SvgTest.php index 7ce417fac..9bfea5d0d 100644 --- a/tests/Conversions/ImageGenerators/SvgTest.php +++ b/tests/Conversions/ImageGenerators/SvgTest.php @@ -20,4 +20,4 @@ expect(mime_content_type($imageFile))->toEqual('image/png'); expect((new Imagick($imageFile))->getImageAlphaChannel())->toBeTrue(); -})->skipWhenRunningLocally(); +});