1.0.0 • Published 4 years ago

metalsmith-minify-avif v1.0.0

Weekly downloads
-
License
AGPLv3
Repository
github
Last release
4 years ago

metalsmith-minify-avif

A metalsmith plugin for minifying AVIF images.

This plugin minifies all of the AVIF images found in Metalsmith files by using the GIMP program. If GIMP is not installed and available on the $PATH, no AVIF images will be minified using this plugin.

Installation

npm install metalsmith-minify-avif

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 minifyAvif = require('metalsmith-minify-avif');

Metalsmith(__dirname)
  .use(minifyAvif())
  .build((err, files) => {
    if (err) { throw err; }
  });

JSON

{
  "plugins": {
    "metalsmith-minify-avif": {}
  }
}

Options

You can pass options to metalsmith-minify-avif 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.
  • quality: optional. The quality of the AVIF file after conversion. Accepts a string or a number. The default is 80.
  • lossy: optional. Whether lossy or lossless compression will be used. Accepts a booleans. The default is false (lossless conversion).

pattern

Only files that match this pattern will be processed for AVIF minification. So this Metalsmith JavaScript configuration or metalsmith.json:

JavaScript

const Metalsmith = require('metalsmith');
const minifyAvif = require('metalsmith-minify-gif');

Metalsmith(__dirname)
  .use(minifyAvif({
    pattern: 'blog/**/*.avif',
  }))
  .build((err, files) => {
    if (err) { throw err; }
  });

JSON

{
  "source": "src",
  "destination": "build",
  "plugins": {
    "metalsmith-minify-avif": {
      "pattern": "blog/**/*.avif"
    }
  }
}

Would only process AVIF files within the ./src/blog folder, because the pattern is relative to your source folder. See multimatch for further details.

quality

The quality parameter sets the level of quality for the minified AVIF image. So this Metalsmith JavaScript configuration or metalsmith.json:

JavaScript

const Metalsmith = require('metalsmith');
const minifyAvif = require('metalsmith-minify-avif');

Metalsmith(__dirname)
  .use(minifyAvif({
    quality: 80,
  }))
  .build((err, files) => {
    if (err) { throw err; }
  });

JSON

{
  "source": "src",
  "destination": "build",
  "plugins": {
    "metalsmith-minify-avif": {
      "quality": 80
    }
  }
}

Would set the level of AVIF quality to 80 when minifying the AVIF file.

lossy

The lossy parameter sets whether lossy or lossless compression will be used when minifying the AVIF file. So this Metalsmith JavaScript configuration or metalsmith.json:

JavaScript

const Metalsmith = require('metalsmith');
const minifyAvif = require('metalsmith-minify-avif');

Metalsmith(__dirname)
  .use(minifyAvif({
    lossy: false,
  }))
  .build((err, files) => {
    if (err) { throw err; }
  });

JSON

{
  "source": "src",
  "destination": "build",
  "plugins": {
    "metalsmith-minify-avif": {
      "lossy": false,
    }
  }
}

Would set lossless compression mode when minifying AVIFs.

License

AGPLv3

1.0.0

4 years ago