Search code examples
c#.netimagemagickanimated-gifmagick.net

Quality drop from 2nd frame GIF Resize Magick.NET


I'm trying to resize a gif using Magick.NET. This gif has 80 frames and resizing it with the code below causes every frame after the first to be extremely blurry and only a little over half of the file size of the first frame.

The only things that change between the first & second frame + everything after that are :

ColorType : TrueColor to TrueColorAlpha
BoundingBox.X : 1 to 2
BoundingBox.Y : 0 to 1
FileSize : 15525 to 9923
HasAlpha : false to true

This is the code i'm using now:

        using (MagickImageCollection collection = new MagickImageCollection(filepath))
        {
            collection.Coalesce();
            int i = 0;

            foreach (MagickImage image in collection)
            {
                image.Resize(newWidth, newHeight);
                image.Write("CompressorTemp\\" + i + ".jpg");
                i++;
            }

            // Save the result
            collection.Write(filepath);
        }

I've only had this happen to this gif but I'll be processing a large amount of them and need to know if this will be an issue.


Solution

  • I am suspecting that you are running into an OpenCL bug that will be fixed in the next release of Magick.NET (7.0.0.0022). A workaround for this is disabling OpenCL:

    MagickNET.UseOpenCL = false;