What is imagemin-gifsicle?
The imagemin-gifsicle npm package is a plugin for Imagemin that uses the Gifsicle library to compress GIF images. It allows you to optimize GIF files by reducing their file size while maintaining quality.
What are imagemin-gifsicle's main functionalities?
Optimization
This feature allows you to optimize GIF images by reducing their file size. The code sample demonstrates how to use imagemin-gifsicle to compress all GIF files in the 'images' directory and save the optimized versions in the 'build/images' directory.
const imagemin = require('imagemin');
const imageminGifsicle = require('imagemin-gifsicle');
(async () => {
await imagemin(['images/*.gif'], {
destination: 'build/images',
plugins: [
imageminGifsicle()
]
});
console.log('GIF images optimized');
})();
Interlacing
This feature allows you to enable interlacing for GIF images. Interlacing loads the image progressively, which can improve the user experience on slow connections. The code sample demonstrates how to enable interlacing while optimizing GIF images.
const imagemin = require('imagemin');
const imageminGifsicle = require('imagemin-gifsicle');
(async () => {
await imagemin(['images/*.gif'], {
destination: 'build/images',
plugins: [
imageminGifsicle({ interlaced: true })
]
});
console.log('GIF images optimized with interlacing');
})();
Color Reduction
This feature allows you to reduce the number of colors in a GIF image, which can significantly reduce the file size. The code sample demonstrates how to reduce the number of colors to 64 while optimizing GIF images.
const imagemin = require('imagemin');
const imageminGifsicle = require('imagemin-gifsicle');
(async () => {
await imagemin(['images/*.gif'], {
destination: 'build/images',
plugins: [
imageminGifsicle({ colors: 64 })
]
});
console.log('GIF images optimized with color reduction');
})();
Other packages similar to imagemin-gifsicle
gifsicle
The gifsicle package is a command-line tool for creating, editing, and optimizing GIF images. It offers similar functionalities to imagemin-gifsicle, such as optimization, interlacing, and color reduction. However, it is not specifically designed to be used as a plugin for Imagemin.
giflossy
The giflossy package is a fork of Gifsicle that includes lossy compression options for GIF images. It provides more aggressive compression techniques compared to imagemin-gifsicle, which can result in smaller file sizes but may also reduce image quality.
imagemin-giflossy
The imagemin-giflossy package is an Imagemin plugin that uses the giflossy library to optimize GIF images. It offers similar functionalities to imagemin-gifsicle but with additional lossy compression options for more aggressive optimization.
imagemin-gifsicle
Imagemin plugin for Gifsicle
Install
$ npm install imagemin-gifsicle
Usage
const imagemin = require('imagemin');
const imageminGifsicle = require('imagemin-gifsicle');
(async () => {
await imagemin(['images/*.gif'], 'build/images', {
use: [
imageminGifsicle()
]
});
console.log('Images optimized');
})();
API
imageminGifsicle([options])(buffer)
Returns a promise for a buffer.
options
Type: Object
interlaced
Type: boolean
Default: false
Interlace gif for progressive rendering.
optimizationLevel
Type: number
Default: 1
Select an optimization level between 1
and 3
.
The optimization level determines how much optimization is done; higher levels take longer, but may have better results.
- Stores only the changed portion of each image.
- Also uses transparency to shrink the file further.
- Try several optimization methods (usually slower, sometimes better results)
colors
Type: number
Reduce the number of distinct colors in each output GIF to num or less. Num must be between 2 and 256.
buffer
Type: Buffer
Buffer to optimize.
License
MIT © imagemin