UNPKG

2.56 kBMarkdownView Raw
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
16const imagemin = require('imagemin');
17const 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
36Returns a `Promise<Buffer>` with the optimized image.
37
38#### options
39
40Type: `object`
41
42##### preset
43
44Type: `string`<br>
45Default: `default`
46
47Preset setting, one of `default`, `photo`, `picture`, `drawing`, `icon` and `text`.
48
49##### quality
50
51Type: `number`<br>
52Default: `75`
53
54Set quality factor between `0` and `100`.
55
56##### alphaQuality
57
58Type: `number`<br>
59Default: `100`
60
61Set transparency-compression quality between `0` and `100`.
62
63##### method
64
65Type: `number`<br>
66Default: `4`
67
68Specify 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
72Type: `number`<br>
73
74Set target size in bytes.
75
76##### sns
77
78Type: `number`<br>
79Default: `80`
80
81Set the amplitude of spatial noise shaping between `0` and `100`.
82
83##### filter
84
85Type: `number`<br>
86
87Set deblocking filter strength between `0` (off) and `100`.
88
89##### autoFilter
90
91Type: `boolean`<br>
92Default: `false`<br>
93
94Adjust filter strength automatically.
95
96##### sharpness
97
98Type: `number`<br>
99Default: `0`
100
101Set filter sharpness between `0` (sharpest) and `7` (least sharp).
102
103##### lossless
104
105Type: `boolean`<br>
106Default: `false`
107
108Encode images losslessly.
109
110##### nearLossless
111
112Type: `number`<br>
113Default: `100`
114
115Encode 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
119Type: `object { x: number, y: number, width: number, height: number }`
120
121Crop the image.
122
123##### resize
124
125Type: `object { width: number, height: number }`
126
127Resize the image. Happens after `crop`.
128
129##### metadata
130
131Type: `string | string[]`<br>
132Default: `none`<br>
133Values: `all` `none` `exif` `icc` `xmp`
134
135A list of metadata to copy from the input to the output if present.
136
137#### buffer
138
139Type: `Buffer`
140
141Buffer to optimize.