From 51303b8bb6621d0c2ac57fbcf88e6f79ab38f134 Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Fri, 8 Dec 2023 16:19:38 +0100 Subject: [PATCH] Refactor code to set default extension to 'jpg' --- .../Actions/PerformManipulationsAction.php | 11 +++++++++-- src/Conversions/ImageGenerators/Svg.php | 2 +- tests/Conversions/ConversionTest.php | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Conversions/Actions/PerformManipulationsAction.php b/src/Conversions/Actions/PerformManipulationsAction.php index 01c0d83c9..fdad211d9 100644 --- a/src/Conversions/Actions/PerformManipulationsAction.php +++ b/src/Conversions/Actions/PerformManipulationsAction.php @@ -30,7 +30,8 @@ public function execute( } $image = Image::useImageDriver(config('media-library.image_driver')) - ->load($conversionTempFile); + ->load($conversionTempFile) + ->format('jpg'); $conversion->getManipulations()->apply($image); @@ -46,7 +47,13 @@ protected function getConversionTempFileName( ): string { $directory = pathinfo($imageFile, PATHINFO_DIRNAME); - $fileName = Str::random(32)."{$conversion->getName()}.{$media->extension}"; + $extension = $media->extension; + + if ($extension === '') { + $extension = 'jpg'; + } + + $fileName = Str::random(32)."{$conversion->getName()}.{$extension}"; return "{$directory}/{$fileName}"; } diff --git a/src/Conversions/ImageGenerators/Svg.php b/src/Conversions/ImageGenerators/Svg.php index 19c5fda4c..7b512edf6 100644 --- a/src/Conversions/ImageGenerators/Svg.php +++ b/src/Conversions/ImageGenerators/Svg.php @@ -25,7 +25,7 @@ public function convert(string $file, Conversion $conversion = null): string public function requirementsAreInstalled(): bool { - return class_exists(\Imagick::class); + return class_exists(Imagick::class); } public function supportedExtensions(): Collection diff --git a/tests/Conversions/ConversionTest.php b/tests/Conversions/ConversionTest.php index 61b34eb65..34b2cb835 100644 --- a/tests/Conversions/ConversionTest.php +++ b/tests/Conversions/ConversionTest.php @@ -134,7 +134,7 @@ ->nonOptimized() ->getManipulations() ->toArray(); - ray($manipulations); + $this->assertArrayNotHasKey('optimize', $manipulations); });