metalsmith-minify-gif v1.0.0
metalsmith-minify-gif
A metalsmith plugin for minifying GIF images.
This plugin minifies all of the GIF images found in Metalsmith files by using the Gifsicle program. If Gifsicle is not installed, minification of GIF images will be skipped.
Installation
npm install metalsmith-minify-gif
Usage
To use this plugin, simply add it to the existing plugins in your Metalsmith source file or include it in the Metalsmith JSON file:
JavaScript
const Metalsmith = require('metalsmith');
const minifyGif = require('metalsmith-minify-gif');
Metalsmith(__dirname)
.use(minifyGif())
.build((err, files) => {
if (err) { throw err; }
});
JSON
{
"plugins": {
"metalsmith-minify-gif": {}
}
}
Options
You can pass options to metalsmith-minify-gif
with the Javascript API or CLI. The options are:
- pattern: optional. Only GIF files that match this pattern will be processed. Accepts a string or an array of strings. The default is
**/*.gif
. - optimize: optional. The optimization level used in the Gifsicle
--optimize
argument. Accepts a string or a number. The default isnull
(no optimization level will be set). - lossy: optional. The level of lossy compression used in the Gifsicle
--lossy
argument. Accepts a string or a number. The default isnull
(no lossy level will be set).
pattern
Only files that match this pattern will be processed for GIF minification. So this Metalsmith JavaScript configuration or metalsmith.json
:
JavaScript
const Metalsmith = require('metalsmith');
const minifyGif = require('metalsmith-minify-gif');
Metalsmith(__dirname)
.use(minifyGif({
pattern: 'blog/**/*.gif',
}))
.build((err, files) => {
if (err) { throw err; }
});
JSON
{
"source": "src",
"destination": "build",
"plugins": {
"metalsmith-minify-gif": {
"pattern": "blog/**/*.gif"
}
}
}
Would only process GIF files within the ./src/blog
folder, because the pattern
is relative to your source folder. See multimatch
for further details.
optimize
The optimize
parameter sets the optimization level when running Gifsicle. So this Metalsmith JavaScript configuration or metalsmith.json
:
JavaScript
const Metalsmith = require('metalsmith');
const minifyGif = require('metalsmith-minify-gif');
Metalsmith(__dirname)
.use(minifyGif({
optimize: 1,
}))
.build((err, files) => {
if (err) { throw err; }
});
JSON
{
"source": "src",
"destination": "build",
"plugins": {
"metalsmith-minify-gif": {
"optimize": 1
}
}
}
Would set the optimization level to 1
when running Gifsicle.
lossy
The lossy
parameter sets the amount of lossy compression when running Gifsicle. So this Metalsmith JavaScript configuration or metalsmith.json
:
JavaScript
const Metalsmith = require('metalsmith');
const minifyGif = require('metalsmith-minify-gif');
Metalsmith(__dirname)
.use(minifyGif({
lossy: 100,
}))
.build((err, files) => {
if (err) { throw err; }
});
JSON
{
"source": "src",
"destination": "build",
"plugins": {
"metalsmith-minify-gif": {
"lossy": 100,
}
}
}
Would set the level of lossy compression to 100
when running Gifsicle.
License
4 years ago