diff --git a/src/Conversions/Actions/PerformManipulationsAction.php b/src/Conversions/Actions/PerformManipulationsAction.php index 4c00bf482..daea7838b 100644 --- a/src/Conversions/Actions/PerformManipulationsAction.php +++ b/src/Conversions/Actions/PerformManipulationsAction.php @@ -20,22 +20,20 @@ public function execute( return $imageFile; } - $conversionTempFile = $this->getConversionTempFileName($media, $conversion, $imageFile); - - File::copy($imageFile, $conversionTempFile); - $supportedFormats = ['jpg', 'pjpg', 'png', 'gif']; if ($conversion->shouldKeepOriginalImageFormat() && in_array($media->extension, $supportedFormats)) { $conversion->format($media->extension); } + $conversionTempFile = $this->getConversionTempFileName($media, $conversion, $imageFile); + $image = Image::useImageDriver(config('media-library.image_driver')) - ->loadFile($conversionTempFile) + ->loadFile($imageFile) ->format('jpg'); $conversion->getManipulations()->apply($image); - $image->save(); + $image->save($conversionTempFile); return $conversionTempFile; } @@ -53,6 +51,11 @@ protected function getConversionTempFileName( $extension = 'jpg'; } + $format = $conversion->getManipulations()->getFirstManipulationArgument('format'); + if($format !== null) { + $extension = $format; + } + $fileName = Str::random(32)."{$conversion->getName()}.{$extension}"; return "{$directory}/{$fileName}";