Fix resizing animated WebP breaking animation#357
Open
deeferentleeg wants to merge 1 commit into
Open
Conversation
ResizeImageAsync used a single MagickImage to read the file, which only reads the first frame of a multi-frame image. For animated WebP (and animated GIF), this discarded all subsequent frames and produced a static image on resize. Detect multi-frame images with the existing ImageAnalyzer.IsAnimated() helper and route them through a new ResizeAnimatedImageAsync method that uses MagickImageCollection: Coalesce, resize each frame, then write the collection back — preserving animation. Single-frame images continue through the original MagickImage path unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #258
Root cause
SaveImageFileHelper.ResizeImageAsyncreads the image with a singleMagickImage, which only reads the first frame of a multi-frame file. For an animated WebP (or animated GIF), every frame after the first is silently discarded, so the resized output is a static image.Fix
Detect multi-frame images using the existing
ImageAnalyzer.IsAnimated(FileInfo)helper (which pings the file withMagickImageCollectionand checksCount > 1). When animated, route through a newResizeAnimatedImageAsyncmethod that:MagickImageCollection(all frames).Coalesce()to expand frame diffs into full frames (per Magick.NET docs).Single-frame images continue through the original
MagickImagepath — no behavior change for PNG, JPEG, static WebP, etc.Notes
MagickImageCollectionpattern already exists in the codebase (TiffManager.LoadTiffPages,ImageAnalyzer.GetImageFrames), so this follows the established convention.ResizeImageAsync.This PR was prepared with AI assistance (code analysis and patch generation).