What is gifsicle?
The gifsicle npm package is a Node.js wrapper for the Gifsicle command-line tool, which is used for manipulating GIF images. It allows you to optimize, resize, and edit GIFs programmatically.
What are gifsicle's main functionalities?
Optimize GIF
This feature allows you to optimize a GIF file to reduce its size. The code sample demonstrates how to use the gifsicle package to optimize an input GIF and save the optimized version as output.gif.
const gifsicle = require('gifsicle');
const execFile = require('child_process').execFile;
execFile(gifsicle, ['--optimize', '--output', 'output.gif', 'input.gif'], (err) => {
if (err) throw err;
console.log('GIF optimized');
});
Resize GIF
This feature allows you to resize a GIF to specified dimensions. The code sample demonstrates how to resize an input GIF to 200x200 pixels and save the resized version as output.gif.
const gifsicle = require('gifsicle');
const execFile = require('child_process').execFile;
execFile(gifsicle, ['--resize', '200x200', '--output', 'output.gif', 'input.gif'], (err) => {
if (err) throw err;
console.log('GIF resized');
});
Extract Frames
This feature allows you to extract individual frames from a GIF. The code sample demonstrates how to extract frames from an input GIF, which will be saved as separate files.
const gifsicle = require('gifsicle');
const execFile = require('child_process').execFile;
execFile(gifsicle, ['--explode', 'input.gif'], (err) => {
if (err) throw err;
console.log('Frames extracted');
});
Other packages similar to gifsicle
gifencoder
The gifencoder package is used for creating GIFs from a series of images or canvas frames. Unlike gifsicle, which focuses on optimizing and editing existing GIFs, gifencoder is more suited for generating new GIFs programmatically.
gif-frames
The gif-frames package allows you to extract frames from a GIF as images. While gifsicle can also extract frames, gif-frames provides more control over the extraction process, such as selecting specific frames or ranges.
sharp
The sharp package is a high-performance image processing library that supports multiple image formats, including GIF. It can resize, crop, and manipulate images, but it is more general-purpose compared to gifsicle, which is specialized for GIFs.
gifsicle-bin
gifsicle manipulates GIF image files in many different ways. Depending on command line options, it can merge several GIFs into a GIF animation; explode an animation into its component frames; change individual frames in an animation; turn interlacing on and off; add transparency and much more.
You probably want imagemin-gifsicle
instead.
Install
$ npm install gifsicle
Usage
import {execFile} from 'node:child_process';
import gifsicle from 'gifsicle';
execFile(gifsicle, ['-o', 'output.gif', 'input.gif'], error => {
console.log('Image minified!');
});
CLI
$ npm install --global gifsicle
$ gifsicle --help