JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 70
  • Score
    100M100P100Q55404F

Node.js wrapper for some images compression algorithms

Package Exports

  • imageoptim

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (imageoptim) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

image-optim Build Status Coverage Status Dependency Status devDependency Status

Node.js wrapper for some images compression algorithms.

Types

Supporting of other types of images is coming soon.

Patches

You can view all the patches which are applied to the algorithms here.

Overview:

  • optipng.patch – adds to OptiPNG the ability to remove RGB components or transparent pixels in RGB+alpha images.

  • zopflipng.patch – makes Zopflipng work on Linux.

Install

$ npm install imageoptim

This command will install image-optim and all supported compression algorithms automatically. The installation of the compression algorithms is subscribed in script env-setup.

Usage

API

var imageOptim = require('imageoptim');

imageOptim.optim

Optimizes the given files.

@param {String[]} – a list of paths to files to optimize
@param {Object} – options:

  • reporters {String[]} - reporters of the results. flat - writes the results to stdout, html - creates the HTML report of the results in file imageoptim-report.html.

@returns {Promise * Object[]} – the information about optimized files:

[{ name: 'file.ext', savedBytes: 12345, exitCode: 0 }]

imageOptim.lint

Checks whether the given files can be optimized further.

@param {String[]} – a list of paths to files to check
@param {Object} – options:

  • tolerance {Number} – sets the measurement error in percentages. The file will be considered to be optimized if the percentage of saved bytes after the compression is less than the specified value.

  • reporters {String[]} - reporters of the results. flat - writes the results to stdout, html - creates the HTML report of the results in file imageoptim-report.html.

@returns {Promise * Object[]} – the information about linted files:

[{ name: 'file.ext', isOptimized: true, exitCode: 0 }]

Exit code

imageOptim.SUCCESS

If a file was processed without errors its exit code will be equal to 0.

imageOptim.CANT_COMPRESS

If a file can not be processed by one of the algorithms its exit code will be equal to 1.

imageOptim.DOESNT_EXIST

If a file does not exist its exit code will be equal to 2.

Example

var imageOptim = require('imageoptim');

// optimization
imageOptim.optim(['1.png', '2.png'], { reporters: ['flat', 'html'] })
    .then(function (res) {
        console.log(res);
    })
    .done();

// linting
imageOptim.lint(['1.png', '2.png'], { tolerance: 0.8, reporters: ['flat', 'html'] })
    .then(function (res) {
        console.log(res);
    })
    .done();

CLI

$ imageoptim --help
Node.js wrapper for some images compression algorithms

Usage:
  imageoptim [OPTIONS] [ARGS]

Options:
  -h, --help : Help
  -v, --version : Shows the version number
  -l, --lint : Lint mode
  -t TOLERANCE, --tolerance=TOLERANCE : Sets the measurement error in percentages (default: 0)
  -r REPORTERS, --reporter=REPORTERS : flat or/and html (default: flat)

Arguments:
  FILES : Paths to files (required)

Example

$ imageoptim path/to/file1 path/to/file2 --reporter=flat --reporter=html # optimization

$ imageoptim path/to/file1 path/to/file2 --lint --tolerance=0.8 --reporter=flat --reporter=html # linting