GIF optimization issue caused by deprecated deconstructImages() in Imagick driver

Painbaker

Well-known member
Affected version
2.3.6
The XenForo Imagick image driver is using the deconstructImages() method, which is no longer recommended for use with animated GIFs. This may be causing unexpected behavior or degraded image quality.


PHP:
    public function save($file, $format = null, $quality = null)
    {
        ....

        switch ($format)
        {
            case IMAGETYPE_GIF:
                if (is_callable([$this->imagick, 'optimizeimagelayers']))
                {
                    $optimized = @$this->imagick->optimizeimagelayers();
                    if ($optimized instanceof \Imagick)
                    {
                        $this->imagick = $optimized;
                    }

                    $deconstructed = @$this->imagick->deconstructImages();
                    if ($deconstructed instanceof \Imagick)
                    {
                        $this->imagick = $deconstructed;
                    }
                }
                $success = $this->imagick->setImageFormat('gif');
                break;
                ....
        }
        ...
        return false;
    }

From ImageMagick documentation:

The traditional way in ImageMagick to optimize an animation, making the result smaller and faster to download and animate, is to "-deconstruct" its "-coalesce" form. This is no longer recommended. Instead you use should use the General GIF Optimizer.

Examples:

Original GIF:
ezgif-116871dc75bd2d.gif

Deconstructed GIF:
1.gif
 
Last edited:
Back
Top Bottom