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.
npm install omggifVerified import paths — ran on the pinned version, not inferred.
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.
For new projects, consider actively maintained alternatives like `gif.js` (for browser-side encoding) or `gifencoder` (Node.js encoding) which provide more modern APIs and ongoing support. For decoding, `gifuct-js` is a popular alternative.
Ensure your project is configured to handle CommonJS modules (e.g., using `require('omggif')` or a bundler that transpiles). If forced to use ES modules, dynamic `import()` or wrapper files might be necessary. Avoid setting `"type": "module"` in package.json without understanding its implications for CJS dependencies.Always allocate a buffer that is generously sized to accommodate all frames and GIF metadata, or implement logic to progressively write to a dynamic buffer if the exact size is unpredictable. The `getOutputBufferPosition()` method can help monitor current usage.
Thoroughly understand the GIF palette specification. Ensure pixel data arrays contain indices that correctly map to the provided palette. Pre-process image data for color reduction and palette generation before passing it to `omggif` for optimal results.
Use CommonJS `require` syntax: `const { GifReader } = require('omggif');`. Alternatively, ensure your build tool (like Webpack or Rollup) is configured to handle CommonJS dependencies within an ESM project, or use dynamic `import('omggif')` for asynchronous loading.Verify the integrity of the GIF data buffer being passed to `GifReader`. Ensure it's a complete and correctly formatted GIF byte stream. Add robust error handling around `GifReader` instantiation to gracefully manage invalid input.
For `GifWriter`, ensure the initial `Uint8Array` buffer is sufficiently large to contain the entire GIF. For `GifReader`, confirm the input buffer actually contains a full GIF and is not truncated. Debug the offsets being accessed if manually manipulating the buffer.
No dependency data recorded yet.