1 | # imagemin-webp [![Build Status](https://travis-ci.org/imagemin/imagemin-webp.svg?branch=master)](https://travis-ci.org/imagemin/imagemin-webp)
|
2 |
|
3 | > WebP [imagemin](https://github.com/imagemin/imagemin) plugin
|
4 |
|
5 |
|
6 | ## Install
|
7 |
|
8 | ```
|
9 | $ npm install imagemin-webp
|
10 | ```
|
11 |
|
12 |
|
13 | ## Usage
|
14 |
|
15 | ```js
|
16 | const imagemin = require('imagemin');
|
17 | const imageminWebp = require('imagemin-webp');
|
18 |
|
19 | (async () => {
|
20 | await imagemin(['images/*.{jpg,png}'], {
|
21 | destination: 'build/images',
|
22 | plugins: [
|
23 | imageminWebp({quality: 50})
|
24 | ]
|
25 | });
|
26 |
|
27 | console.log('Images optimized');
|
28 | })();
|
29 | ```
|
30 |
|
31 |
|
32 | ## API
|
33 |
|
34 | ### imageminWebp(options?)(buffer)
|
35 |
|
36 | Returns a `Promise<Buffer>` with the optimized image.
|
37 |
|
38 | #### options
|
39 |
|
40 | Type: `object`
|
41 |
|
42 | ##### preset
|
43 |
|
44 | Type: `string`<br>
|
45 | Default: `default`
|
46 |
|
47 | Preset setting, one of `default`, `photo`, `picture`, `drawing`, `icon` and `text`.
|
48 |
|
49 | ##### quality
|
50 |
|
51 | Type: `number`<br>
|
52 | Default: `75`
|
53 |
|
54 | Set quality factor between `0` and `100`.
|
55 |
|
56 | ##### alphaQuality
|
57 |
|
58 | Type: `number`<br>
|
59 | Default: `100`
|
60 |
|
61 | Set transparency-compression quality between `0` and `100`.
|
62 |
|
63 | ##### method
|
64 |
|
65 | Type: `number`<br>
|
66 | Default: `4`
|
67 |
|
68 | Specify the compression method to use, between `0` (fastest) and `6` (slowest). This parameter controls the trade off between encoding speed and the compressed file size and quality.
|
69 |
|
70 | ##### size
|
71 |
|
72 | Type: `number`<br>
|
73 |
|
74 | Set target size in bytes.
|
75 |
|
76 | ##### sns
|
77 |
|
78 | Type: `number`<br>
|
79 | Default: `80`
|
80 |
|
81 | Set the amplitude of spatial noise shaping between `0` and `100`.
|
82 |
|
83 | ##### filter
|
84 |
|
85 | Type: `number`<br>
|
86 |
|
87 | Set deblocking filter strength between `0` (off) and `100`.
|
88 |
|
89 | ##### autoFilter
|
90 |
|
91 | Type: `boolean`<br>
|
92 | Default: `false`<br>
|
93 |
|
94 | Adjust filter strength automatically.
|
95 |
|
96 | ##### sharpness
|
97 |
|
98 | Type: `number`<br>
|
99 | Default: `0`
|
100 |
|
101 | Set filter sharpness between `0` (sharpest) and `7` (least sharp).
|
102 |
|
103 | ##### lossless
|
104 |
|
105 | Type: `boolean`<br>
|
106 | Default: `false`
|
107 |
|
108 | Encode images losslessly.
|
109 |
|
110 | ##### nearLossless
|
111 |
|
112 | Type: `number`<br>
|
113 | Default: `100`
|
114 |
|
115 | Encode losslessly with an additional [lossy pre-processing step](https://groups.google.com/a/webmproject.org/forum/#!msg/webp-discuss/0GmxDmlexek/3ggyYsaYdFEJ), with a quality factor between `0` (maximum pre-processing) and `100` (same as `lossless`).
|
116 |
|
117 | ##### crop
|
118 |
|
119 | Type: `object { x: number, y: number, width: number, height: number }`
|
120 |
|
121 | Crop the image.
|
122 |
|
123 | ##### resize
|
124 |
|
125 | Type: `object { width: number, height: number }`
|
126 |
|
127 | Resize the image. Happens after `crop`.
|
128 |
|
129 | ##### metadata
|
130 |
|
131 | Type: `string | string[]`<br>
|
132 | Default: `none`<br>
|
133 | Values: `all` `none` `exif` `icc` `xmp`
|
134 |
|
135 | A list of metadata to copy from the input to the output if present.
|
136 |
|
137 | #### buffer
|
138 |
|
139 | Type: `Buffer`
|
140 |
|
141 | Buffer to optimize.
|