Greatly improve the performance of GIF processing with ImageMagick
authorAlexander Ebert <ebert@woltlab.com>
Sat, 12 Dec 2020 17:41:36 +0000 (18:41 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 12 Dec 2020 17:41:36 +0000 (18:41 +0100)
wcfsetup/install/files/lib/system/image/adapter/ImagickImageAdapter.class.php

index 38754775dfb48ce955cb66ace93744e92433183e..e690e2a618c104da0cbf00c96c05b4655b475cc6 100644 (file)
@@ -356,6 +356,16 @@ class ImagickImageAdapter implements IImageAdapter {
                        fclose($file);
                }
                else {
+                       // Greatly reduces the time required to create the image and drastically
+                       // reduces the filesize to more reasonable levels without a visible
+                       // quality loss.
+                       //
+                       // See https://github.com/Imagick/imagick/issues/360
+                       if ($image->getImageFormat() == 'GIF') {
+                               $image = $image->deconstructImages();
+                               $image->quantizeImages(256, \Imagick::COLORSPACE_SRGB, 0, false, false);
+                       }
+                       
                        $image->writeImages($filename, true);
                }
        }