UNPKG

1.21 kBMarkdownView Raw
1# image-min [![Build Status](https://travis-ci.org/kevva/image-min.svg?branch=master)](https://travis-ci.org/kevva/image-min)
2
3> Minify images seamlessly with Node.js.
4
5## Install
6
7```bash
8$ npm install --save image-min
9```
10
11## Usage
12
13```js
14var Imagemin = require('image-min');
15var jpegtran = require('image-min').jpegtran;
16
17var imagemin = new Imagemin()
18 .src('foo.jpg')
19 .dest('foo-optimized.jpg')
20 .use(jpegtran({ progressive: true }));
21
22imagemin.optimize(function (err, file) {
23 console.log(file);
24 // => { contents: <Buffer 89 50 4e ...>, mode: '0644', origSize: 50986, destSize: 46987 }
25});
26```
27
28## API
29
30### new Imagemin()
31
32Creates a new `Imagemin` instance.
33
34### .use(plugin)
35
36Add a `plugin` to the middleware stack.
37
38### .src(file)
39
40Set the file to be optimized. Could be a `Buffer` or the path to a file.
41
42### .dest(file)
43
44Set the destination to where your file will be written. If you don't set any destination
45the file won't be written.
46
47### .optimize(cb)
48
49Optimize your file with the given settings.
50
51### .run(file, cb)
52
53Run all middleware plugins on your file.
54
55## License
56
57[MIT License](http://en.wikipedia.org/wiki/MIT_License) © [Kevin Mårtensson](http://kevinmartensson.com)