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
|
14 | var Imagemin = require('image-min');
|
15 | var jpegtran = require('image-min').jpegtran;
|
16 |
|
17 | var imagemin = new Imagemin()
|
18 | .src('foo.jpg')
|
19 | .dest('foo-optimized.jpg')
|
20 | .use(jpegtran({ progressive: true }));
|
21 |
|
22 | imagemin.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 |
|
32 | Creates a new `Imagemin` instance.
|
33 |
|
34 | ### .use(plugin)
|
35 |
|
36 | Add a `plugin` to the middleware stack.
|
37 |
|
38 | ### .src(file)
|
39 |
|
40 | Set the file to be optimized. Could be a `Buffer` or the path to a file.
|
41 |
|
42 | ### .dest(file)
|
43 |
|
44 | Set the destination to where your file will be written. If you don't set any destination
|
45 | the file won't be written.
|
46 |
|
47 | ### .optimize(cb)
|
48 |
|
49 | Optimize your file with the given settings.
|
50 |
|
51 | ### .run(file, cb)
|
52 |
|
53 | Run 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)
|