{"library":"omggif","title":"GIF 89a Encoder/Decoder","description":"omggif is a JavaScript library designed for low-level encoding and decoding of GIF 89a format images. It provides explicit `GifReader` and `GifWriter` classes that operate directly on byte buffers, typically `Uint8Array`s or Node.js `Buffer`s. This gives developers granular control over every aspect of GIF generation, including frame dimensions, color palettes, delays, and other GIF specification details. First released in 2013 and last updated to version 1.0.10 in June 2017, the package is considered abandoned and has received no further maintenance or feature updates. While historically useful for both browser and Node.js environments due to its lightweight and pure JavaScript implementation, modern projects might find it lacks contemporary features, active community support, or the high-level abstractions found in more actively maintained GIF manipulation libraries.","language":"javascript","status":"abandoned","last_verified":"Sun Apr 19","install":{"commands":["npm install omggif"],"cli":null},"imports":["const { GifReader } = require('omggif');","const { GifWriter } = require('omggif');","const omggif = require('omggif');\nconst reader = new omggif.GifReader(...);"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const { GifWriter, GifReader } = require('omggif');\n\n// --- Encoding a simple GIF ---\nconst width = 100;\nconst height = 100;\nconst frameCount = 2;\n\n// A generous buffer size for a 2-frame, 100x100 GIF with a palette\n// Realistically, calculate based on (width * height * numFrames) + header/metadata overhead\nconst outputBuffer = new Uint8Array((width * height * frameCount * 2) + 768); \n\nconst writer = new GifWriter(outputBuffer, width, height, { loop: 0 });\n\n// Define a simple palette (red, blue)\nconst palette = [\n  0xFF0000, // Red\n  0x0000FF  // Blue\n];\n\n// Frame 1: All red pixels (index 0 in palette)\nconst pixels1 = new Uint8Array(width * height).fill(0);\nwriter.addFrame(0, 0, width, height, pixels1, { palette, delay: 20 }); // 20ms delay\n\n// Frame 2: All blue pixels (index 1 in palette)\nconst pixels2 = new Uint8Array(width * height).fill(1);\nwriter.addFrame(0, 0, width, height, pixels2, { palette, delay: 20 }); // 20ms delay\n\n// Finalize the GIF and get the actual size\nconst finalSize = writer.end();\nconst encodedGifBuffer = outputBuffer.slice(0, finalSize);\n\nconsole.log(`Generated GIF of size: ${finalSize} bytes`);\n// In a Node.js environment, you could save this:\n// require('fs').writeFileSync('output.gif', encodedGifBuffer);\n\n// --- Decoding a GIF (example with a dummy buffer) ---\n// For actual use, 'gifDataBuffer' would come from a file read or network request\n// This is a minimal valid 1x1 GIF (header + LSD + GCT + IMG descriptor + LZW data + trailer)\nconst dummyGifDataBuffer = new Uint8Array([\n  0x47, 0x49, 0x46, 0x38, 0x39, 0x61, // GIF89a\n  0x01, 0x00, 0x01, 0x00,             // 1x1 canvas\n  0x80, 0x00, 0x00,                   // GCT present, 2 colors (2^1)\n  0xFF, 0xFF, 0xFF,                   // White (index 0)\n  0x00, 0x00, 0x00,                   // Black (index 1)\n  0x2C, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, // Image Descriptor: 1x1 at 0,0\n  0x02,                               // LZW Minimum Code Size\n  0x02, 0x4C, 0x01,                   // LZW Data (clear, data, EOI)\n  0x3B                                // GIF Trailer\n]);\n\ntry {\n  const reader = new GifReader(dummyGifDataBuffer);\n  console.log(`Decoded GIF: ${reader.width}x${reader.height}, ${reader.numFrames()} frame(s)`);\n\n  if (reader.numFrames() > 0) {\n    const frameInfo = reader.frameInfo(0);\n    console.log(`  First frame dimensions: ${frameInfo.width}x${frameInfo.height}`);\n    // To get pixel data, you'd use decodeAndBlitFrameRGBA:\n    // const pixelsRGBA = new Uint8Array(frameInfo.width * frameInfo.height * 4);\n    // reader.decodeAndBlitFrameRGBA(0, pixelsRGBA);\n  }\n} catch (e) {\n  console.error(\"Error reading GIF data:\", e.message);\n}\n","lang":"javascript","description":"This quickstart demonstrates how to use `omggif` to encode a simple two-frame animated GIF from raw pixel data and then how to initialize a `GifReader` for a given GIF byte buffer to extract metadata like dimensions and frame count. It highlights the low-level byte buffer manipulation required by the library.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}