imagemin

[Unmaintained] Minify images seamlessly

README

imagemin


Minify images seamlessly


Sindre Sorhus' open source work is supported by the community

Special thanks to: Strapi is the leading open-source headless CMS.It’s 100% JavaScript, fully customizable, and developer-first.

Install


  1. ``` shell
  2. npm install imagemin
  3. ```

Usage


  1. ``` js
  2. import imagemin from 'imagemin';
  3. import imageminJpegtran from 'imagemin-jpegtran';
  4. import imageminPngquant from 'imagemin-pngquant';

  5. const files = await imagemin(['images/*.{jpg,png}'], {
  6. destination: 'build/images',
  7. plugins: [
  8.   imageminJpegtran(),
  9.   imageminPngquant({
  10.    quality: [0.6, 0.8]
  11.   })
  12. ]
  13. });

  14. console.log(files);
  15. //=> [{data: , destinationPath: 'build/images/foo.jpg'}, …]
  16. ```

API


imagemin(input, options?)


Returns `Promise`in the format `{data: Uint8Array, sourcePath: string, destinationPath: string}`.

input


Type: string[]

File paths or glob patterns .

options


Type: object

destination

Type: string

Set the destination folder to where your files will be written. If no destination is specified, no files will be written.

plugins

Type: Array

The plugins to use.

glob

Type: booleanDefault: true

Enable globbing when matching file paths.

imagemin.buffer(data, options?)


Returns `Promise`.

data


Type: Uint8Array

The image data to optimize.

options


Type: object

plugins

Type: Array

Plugins to use.

Related


imagemin-cli - CLI for this module
gulp-imagemin - Gulp plugin