diff --git a/app/Livewire/Questions/Create.php b/app/Livewire/Questions/Create.php index d454c05b9..9c527e3ee 100644 --- a/app/Livewire/Questions/Create.php +++ b/app/Livewire/Questions/Create.php @@ -294,12 +294,23 @@ public function optimizeImage(string $path): void $imagePath = Storage::disk('public')->path($path); $imagick = new Imagick($imagePath); - $imagick->resizeImage(1000, 1000, Imagick::FILTER_LANCZOS, 1, true); - - $imagick->stripImage(); - - $imagick->setImageCompressionQuality(80); - $imagick->writeImage($imagePath); + if ($imagick->getNumberImages() > 1) { + $imagick = $imagick->coalesceImages(); + + foreach ($imagick as $frame) { + $frame->resizeImage(1000, 1000, Imagick::FILTER_LANCZOS, 1, true); + $frame->stripImage(); + $frame->setImageCompressionQuality(80); + } + + $imagick = $imagick->deconstructImages(); + $imagick->writeImages($imagePath, true); + } else { + $imagick->resizeImage(1000, 1000, Imagick::FILTER_LANCZOS, 1, true); + $imagick->stripImage(); + $imagick->setImageCompressionQuality(80); + $imagick->writeImage($imagePath); + } $imagick->clear(); $imagick->destroy();