npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

imageoptim

v0.5.0

Published

Node.js wrapper for some images compression algorithms

Downloads

108

Readme

image-optim Build Status Coverage Status Dependency Status devDependency Status

Node.js wrapper for image 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 (default: flat).

@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 (decimal < 1) or bytes (integer or decimal >= 1) (default: 0).

type | skope | description --- | --- | --- percentages | < 1 | The file will be considered to be optimized if the percentage of saved bytes after the compression is less than the specified value (0.880%, 0.011%, etc) bytes | >= 1 | The file will be considered to be optimized if the number of saved bytes after the compression is less than the specified value (2020 bytes, 100500100500 bytes, etc)

  • 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 (default: flat).

@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.08,
        // tolerance: 20,
        reporters: ['flat', 'html']
    })
    .then(function (res) {
        console.log(res);
    })
    .done();

CLI

$ imageoptim --help
Node.js wrapper for image 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 or bytes (default: 0)
  -r REPORTERS, --reporter=REPORTERS : flat or/and html (default: flat)

Arguments:
  FILES : Paths to files (required)

REMARK! More information about options lint and tolerance can be found in the API.

Example

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

$ imageoptim path/to/file --lint --tolerance=0.08 --reporter=flat --reporter=html # linting, tolerance is `8%`

$ imageoptim path/to/file --lint --tolerance=20 # linting, tolerance is `20 bytes`