dlemstra / Magick.NET

The .NET library for ImageMagick
Apache License 2.0
3.46k stars 415 forks source link

Regression: Can't read and write animated WebP images anymore #1349

Closed rpnetcoder closed 1 year ago

rpnetcoder commented 1 year ago

Magick.NET version

Magick.NET-Q16-AnyCPU, 12.3.0

Environment (Operating system, version and so on)

Window 10, x64

Description

Comparing to Magick.NET 9.1.2, the newest Magick.NET 12.3.0 fails to read/write any animated WebP images I have tried.

Steps to Reproduce

Please execute the following code with predefined animated WebP encoded to base64 with Magick.NET-Q16-AnyCPU, 12.3.0. This code doesn't fail with Magick.NET-Q16-AnyCPU, 9.1.2.

`string animatedWebpBase64 = "UklGRigcAABXRUJQVlA4WAoAAAASAAAAVAAAKAAAQU5JTQYAAAAAAAAAAABBTk1GhAEAAAMAAAMAAEoAABwAAGQAAANWUDhMawEAAC9KAAcQfyAQSFLYH3iFiZiI+U/ANpBsa9uxN3fsvOv+EI7e2E5qtwdg27Zmtm3bxtAY2u7QttsP//OfQUT/JwCBvt03oW3bcXEI8tt8um4N0lzDTV9KCMZCgz6XK7HTufSrlycKHbKp/ZB6+ncFoGOCv7dFDLznytWrZlcn+htiCrhm+OvGckuIW/1ssPXNBlJNfEw0+EkdMoUY43GlDnUC3iZLRbjtyaF+BuCQ1DXHwv6kvgsAb02hyQobckhOTYBrYLppC7OZqXHIJvXK33A9Tef2Ocle5169efQ69xjKqHvfg+cix2Qg3SsSAC4n4so9BZ+HSJYrIJnUmSQnQ9gijwBvLW558Mggr0olkzoek9hEASnkU6muJCNRyskAhpOLpZBLjnxiMgoAbOo4qVO1yOVsohwLyXApnCbJlnAtZIgYhvl5m1oeJ/bW8IFGPCKGKwUc6fEkmRfFMIk9PdCY5XKYe9ILG/YoBwBBTk1GXgEAAAMAAAIAAEkAAB4AAGQAAAFWUDhMRQEAAC9JgAcQfyAQSFLYH3iFiZiI+U/ANoBj29qx5/lt3N//38WqnMro0dpm6yoDSG/0ZpdMwHZa28and2UCEf2fAPqviwcf7JabY/2zZ0yMRuz4G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hmi6H0iJTwF89rfRMExGN/nr4kBCqCNX1a77MfkthvUpRgulzw7csgNOJHFMKYkTAsBnZ0leAniY58BaKHpKoi0GA8loa6VCWdYPHRm0ZQ/lV46SbuBw9q2AeoWkC+j8HKknOq0olPypB59ddVgCOLwJ/VFkUJijSq2A5B6SDe8G4xVMIXuFJN/gkxNJLytpKHcgg6zgRpJf5aHDx4EX8AgKIGvt5OHFolO0vScjSdZfkwcst9i4k4wNSZuwNQCAsvTGvQ8ff9njfw=="; byte[] animatedWebpBytes = Convert.FromBase64String(animatedWebpBase64);

        using (MagickImageCollection image = new MagickImageCollection(animatedWebpBytes))
        {
            /* 
                Magick.NET-Q16-AnyCPU" Version="9.1.2": NO ERRORS
                Magick.NET-Q16-AnyCPU" Version="12.3.0": ERROR adding frame: Invalid frame dimensions. `' @ error/webp.c/WriteAnimatedWEBPImage/965
            */
            byte[] imageBytes = image.ToByteArray();

            using (MemoryStream memStream = new MemoryStream())
            {
                /* 
                    Magick.NET-Q16-AnyCPU" Version="9.1.2": NO ERRORS
                    Magick.NET-Q16-AnyCPU" Version="12.3.0": ERROR adding frame: Invalid frame dimensions. `' @ error/webp.c/WriteAnimatedWEBPImage/965
                */
                image.Write(memStream);
            }
        }`
dlemstra commented 1 year ago

An earlier version of ImageMagick would automatically do a call to image.Coalesce() before saving the image but this had to be removed because it would cause issues when a user already did this themselves. So you will now need to do this yourself before saving the image.

rpnetcoder commented 1 year ago

Calling image.Coalesce() for the code above is helpful. However, there is some side effect. Consider the usual flow: image.Coalesce() -> [do something with image] -> image.Optimize() -> image.ToByteArray(). The last call image.ToByteArray() will fail for animated WebP (but NOT for GIF) if do not remove image.Optimize() call from the chain. In its turn, removing image.Optimize() will cause little larger image weight for animated WebP and inconsistency of WebP vs GIF image handling.

dlemstra commented 1 year ago

The call to Coalesce() was always done before saving the WebP image but you will now need to do it yourself.

rpnetcoder commented 1 year ago

Thanks for the clarification