Skip to content

GIF support#102

Closed
xfalcox wants to merge 3 commits into
jamsinclair:mainfrom
xfalcox:claude/add-gif-decoder
Closed

GIF support#102
xfalcox wants to merge 3 commits into
jamsinclair:mainfrom
xfalcox:claude/add-gif-decoder

Conversation

@xfalcox
Copy link
Copy Markdown

@xfalcox xfalcox commented Mar 30, 2026

This PR adds a gif package with decode support.

The idea is to eventually be able to offer GIF -> Animated WEBP / Animated AVIF using jSquash packages

xfalcox and others added 3 commits March 30, 2026 15:22
New decode-only package using giflib to decode GIF images to ImageData,
following the same WASM + Emscripten pattern as existing codecs.
Decodes the first frame of animated GIFs with transparency support.

Compiled WASM is only ~21KB since giflib is lightweight.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- decodeAnimated(): returns array of {imageData, duration} for each frame
  with proper disposal method handling (background restore, previous restore)
- isAnimated(): returns boolean indicating if GIF has multiple frames
- decode() still returns first frame as ImageData (unchanged)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Checks for GIF87a/GIF89a header and throws a clear error message
when the file is not a valid GIF (e.g. a WebP with a .gif extension).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jamsinclair
Copy link
Copy Markdown
Owner

Thanks @xfalcox. This is awesome.

If it's ok, I'll take a look at these PRs over the weekend and get back to you with any comments 🙏

To help my understanding, any strong motivating choices for the gif decoder library choice (giflib)? I know there's quite a few out there.

@xfalcox
Copy link
Copy Markdown
Author

xfalcox commented Mar 31, 2026

To help my understanding, any strong motivating choices for the gif decoder library choice (giflib)? I know there's quite a few out there.

Not really any strong reasons for it, we could even swap for a Rust based one if you prefer.

From a basic research good candidates are:

I will create an alternative PR with the Rust one instead.

@xfalcox
Copy link
Copy Markdown
Author

xfalcox commented Apr 2, 2026

Closed in favor of #104

@xfalcox xfalcox closed this Apr 2, 2026
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.

2 participants