What is omggif?
The omggif npm package is a JavaScript library for reading and writing GIF89a encoded GIF files. It allows for parsing and creating GIFs in a Node.js environment or in the browser. This package is particularly useful for applications that need to manipulate GIF images programmatically, such as generating GIFs on-the-fly, modifying existing GIFs, or extracting information from GIF files.
What are omggif's main functionalities?
Reading GIF Information
This feature allows you to read and extract information from a GIF file, such as its dimensions. The code sample demonstrates how to read a GIF file and log its width and height.
const GifReader = require('omggif').GifReader;
const fs = require('fs');
fs.readFile('path/to/gif.gif', (err, data) => {
if (err) throw err;
const reader = new GifReader(data);
console.log('Width:', reader.width);
console.log('Height:', reader.height);
});
Writing GIF Images
This feature enables the creation of GIF files programmatically. The code sample shows how to initialize a GIF writer, add a frame to the GIF, and save the GIF to a file.
const GifWriter = require('omggif').GifWriter;
const fs = require('fs');
const buffer = new Uint8Array(256 * 256 * 5); // Example buffer size
const writer = new GifWriter(buffer, 256, 256, { loop: 0 });
// Add frames to the GIF
writer.addFrame(0, 0, 256, 256, frameData, { delay: 50 });
fs.writeFile('path/to/output.gif', buffer, (err) => {
if (err) throw err;
console.log('GIF created successfully.');
});
Other packages similar to omggif
gifencoder
gifencoder is a server-side node.js GIF encoding library that creates GIF images. It is similar to omggif in that it allows for the creation of GIFs programmatically but differs in its API and additional features like setting quality and repeat options for the GIF.
jsgif
jsgif is a JavaScript GIF parser and player which works in both the browser and Node.js environments. It shares functionality with omggif in terms of reading GIF files but focuses more on playing GIF animations rather than creating or modifying them.
omggif is a JavaScript implementation of a GIF 89a encoder and decoder.
https://github.com/deanm/omggif
(c) Dean McNamee dean@gmail.com, 2013.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.