Local Browser GIF89a Encoder
A minimal, zero-dependency JavaScript library for turning photos or Canvas frames into animated GIFs directly inside the user's browser — no server uploads, no FFmpeg WASM bundle, and no watermarks. Built as an open-source reference alongside the browser-local Liofx Photo to GIF studio.
Interactive On-Device Photo to GIF Demo
Pick 2–12 JPEG, PNG, or WebP images from your device (everything stays in browser memory), or load 3 generated demo frames to test instantly.
Need More Editing Controls Without Uploading Photos?
This repository keeps the core GIF89a encoder tiny (~250 lines) for developers learning or embedding local GIF export.
If you want a full-featured, watermark-free web studio with per-frame timing, reverse & ping-pong playback,
crossfade transitions, custom canvas aspect ratios, and drag-to-reorder frames — still 100% on-device with zero uploads —
try the free Liofx Photo to GIF converter.
Need other local utilities without server uploads? Browse all 15 free on-device creative tools on Liofx, including Video to GIF, Live Photo Maker, Image Resizer, and Image Compressor.
How the Encoder Works in Plain JavaScript
- Canvas normalization: Each source image is scaled cleanly onto an offscreen HTML5 Canvas so every frame shares exact width and height dimensions.
- 256-color quantization: Pixels are mapped to a balanced 216-color RGB cube plus a 40-step grayscale ramp, with optional Floyd-Steinberg error diffusion for smoother gradients.
- Variable-width LZW compression: Encodes 8-bit palette indices into standard GIF89a sub-blocks with dynamic dictionary reset at 4,096 codes.
- Zero network transfer: Output bytes become a local
BlobURL in RAM — ideal for privacy-sensitive workflows and offline PWAs.
import { encodeGif } from './src/gif-encoder.js';
const gifBytes = encodeGif(
[
{ rgba: frame1ImageData.data, delayMs: 400 },
{ rgba: frame2ImageData.data, delayMs: 400 },
],
{ width: 360, height: 240, loop: 0, dither: true }
);
const blobUrl = URL.createObjectURL(new Blob([gifBytes], { type: 'image/gif' }));