discord / lilliput

Resize images and animated GIFs in Go
https://discord.com/blog/how-discord-resizes-150-million-images-every-day-with-go-and-c
Other
1.96k stars 123 forks source link

fix: Report frame-count, dispose-method, and background-color from GIF for use with animated WebP #200

Closed skidder closed 1 week ago

skidder commented 1 week ago

This PR enhances the GIF decoder to properly handle animated GIF to WebP conversion, focusing on frame disposal methods and animation metadata.

Key Improvements

  1. Proper Frame Disposal

    • Maps GIF disposal methods to WebP equivalents
    • Fixes visual artifacts in animations with transparent regions
    • Properly handles frame-to-frame transitions
  2. Animation Metadata

    • Combined loop count and frame count reading into single pass
    • Cached animation info to prevent redundant processing
    • More accurate frame counting
  3. Performance

    • Single-pass metadata reading
    • Cached animation information
    • Reduced file parsing overhead

These changes ensure that animated GIFs are correctly converted to WebP format while maintaining visual fidelity and animation timing.