Skip to content

Fix resizing animated WebP breaking animation#357

Open
deeferentleeg wants to merge 1 commit into
Ruben2776:devfrom
deeferentleeg:fix/issue-258-animated-webp-resize
Open

Fix resizing animated WebP breaking animation#357
deeferentleeg wants to merge 1 commit into
Ruben2776:devfrom
deeferentleeg:fix/issue-258-animated-webp-resize

Conversation

@deeferentleeg

Copy link
Copy Markdown
Contributor

Closes #258

Root cause

SaveImageFileHelper.ResizeImageAsync reads the image with a single MagickImage, 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 with MagickImageCollection and checks Count > 1). When animated, route through a new ResizeAnimatedImageAsync method that:

  1. Reads the file as a MagickImageCollection (all frames).
  2. Calls Coalesce() to expand frame diffs into full frames (per Magick.NET docs).
  3. Resizes each frame individually.
  4. Writes the collection back, preserving animation timing.

Single-frame images continue through the original MagickImage path — no behavior change for PNG, JPEG, static WebP, etc.

Notes

  • The MagickImageCollection pattern already exists in the codebase (TiffManager.LoadTiffPages, ImageAnalyzer.GetImageFrames), so this follows the established convention.
  • The fix also benefits animated GIFs, which had the same single-frame problem in the batch resize path.
  • No public API change; one new private method + a 9-line guard at the top of ResizeImageAsync.

This PR was prepared with AI assistance (code analysis and patch generation).

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resizing animated Webp breaks animation

1 participant