You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.0 KiB

4 years ago
# imagemin [![Build Status](https://travis-ci.org/imagemin/imagemin.svg?branch=master)](https://travis-ci.org/imagemin/imagemin) [![Build status](https://ci.appveyor.com/api/projects/status/wlnem7wef63k4n1t?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/imagemin)
> Minify images seamlessly
## Install
```
$ npm install imagemin
```
## Usage
```js
const imagemin = require('imagemin');
const imageminJpegtran = require('imagemin-jpegtran');
const imageminPngquant = require('imagemin-pngquant');
(async () => {
const files = await imagemin(['images/*.{jpg,png}'], 'build/images', {
plugins: [
imageminJpegtran(),
imageminPngquant({quality: '65-80'})
]
});
console.log(files);
//=> [{data: <Buffer 89 50 4e >, path: 'build/images/foo.jpg'}, …]
})();
```
## API
### imagemin(input, [output], [options])
Returns `Promise<Object[]>` in the format `{data: Buffer, path: string}`.
#### input
Type: `string[]`
Files to be optimized. See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage).
#### output
Type: `string`
Set the destination folder to where your files will be written. If no destination is specified no files will be written.
#### options
Type: `Object`
##### plugins
Type: `Array`
[Plugins](https://www.npmjs.com/browse/keyword/imageminplugin) to use.
### imagemin.buffer(buffer, [options])
Returns `Promise<Buffer>`.
#### buffer
Type: `Buffer`
Buffer to optimize.
#### options
Type: `Object`
##### plugins
Type: `Array`
[Plugins](https://www.npmjs.com/browse/keyword/imageminplugin) to use.
## Related
- [imagemin-cli](https://github.com/imagemin/imagemin-cli) - CLI for this module
- [imagemin-app](https://github.com/imagemin/imagemin-app) - GUI app for this module
- [gulp-imagemin](https://github.com/sindresorhus/gulp-imagemin) - Gulp plugin
- [grunt-contrib-imagemin](https://github.com/gruntjs/grunt-contrib-imagemin) - Grunt plugin
## License
MIT © [imagemin](https://github.com/imagemin)