1 | # imagemin-mozjpeg [![Build Status](https://travis-ci.org/imagemin/imagemin-mozjpeg.svg?branch=master)](https://travis-ci.org/imagemin/imagemin-mozjpeg) [![Build status](https://ci.appveyor.com/api/projects/status/uuh7yi48erf4ykyo?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/imagemin-mozjpeg)
|
2 |
|
3 | > [Imagemin](https://github.com/imagemin/imagemin) plugin for [mozjpeg](https://github.com/mozilla/mozjpeg)
|
4 |
|
5 |
|
6 | ## Install
|
7 |
|
8 | ```
|
9 | $ npm install imagemin-mozjpeg
|
10 | ```
|
11 |
|
12 |
|
13 | ## Usage
|
14 |
|
15 | ```js
|
16 | const imagemin = require('imagemin');
|
17 | const imageminMozjpeg = require('imagemin-mozjpeg');
|
18 |
|
19 | (async () => {
|
20 | await imagemin(['images/*.jpg'], 'build/images', {
|
21 | use: [
|
22 | imageminMozjpeg()
|
23 | ]
|
24 | });
|
25 |
|
26 | console.log('Images optimized');
|
27 | })();
|
28 | ```
|
29 |
|
30 |
|
31 | ## API
|
32 |
|
33 | ### imageminMozjpeg([options])(buffer)
|
34 |
|
35 | Returns a `Promise<Buffer>`.
|
36 |
|
37 | #### options
|
38 |
|
39 | ##### quality
|
40 |
|
41 | Type: `number`
|
42 |
|
43 | Compression quality, in range `0` (worst) to `100` (perfect).
|
44 |
|
45 | ##### progressive
|
46 |
|
47 | Type: `boolean`<br>
|
48 | Default: `true`
|
49 |
|
50 | `false` creates baseline JPEG file.
|
51 |
|
52 | ##### targa
|
53 |
|
54 | Type: `boolean`<br>
|
55 | Default: `false`
|
56 |
|
57 | Input file is Targa format (usually not needed).
|
58 |
|
59 | ##### revert
|
60 |
|
61 | Type: `boolean`<br>
|
62 | Default: `false`
|
63 |
|
64 | Revert to standard defaults instead of mozjpeg defaults.
|
65 |
|
66 | ##### fastCrush
|
67 |
|
68 | Type: `boolean`<br>
|
69 | Default: `false`
|
70 |
|
71 | Disable progressive scan optimization.
|
72 |
|
73 | ##### dcScanOpt
|
74 |
|
75 | Type: `number`<br>
|
76 | Default: `1`
|
77 |
|
78 | Set DC scan optimization mode.
|
79 |
|
80 | - `0` One scan for all components
|
81 | - `1` One scan per component
|
82 | - `2` Optimize between one scan for all components and one scan for 1st component plus one scan for remaining components
|
83 |
|
84 | ##### trellis
|
85 |
|
86 | Type: `boolean`<br>
|
87 | Default: `true`
|
88 |
|
89 | [Trellis optimization](https://en.wikipedia.org/wiki/Trellis_quantization).
|
90 |
|
91 | ##### trellisDC
|
92 |
|
93 | Type: `boolean`<br>
|
94 | Default: `true`
|
95 |
|
96 | Trellis optimization of DC coefficients.
|
97 |
|
98 | ##### tune
|
99 |
|
100 | Type: `string`<br>
|
101 | Default: `hvs-psnr`
|
102 |
|
103 | Set Trellis optimization method. Available methods: `psnr`, `hvs-psnr`, `ssim`, `ms-ssim`
|
104 |
|
105 | ##### overshoot
|
106 |
|
107 | Type: `boolean`<br>
|
108 | Default: `true`
|
109 |
|
110 | Black-on-white deringing via overshoot.
|
111 |
|
112 | ##### arithmetic
|
113 |
|
114 | Type: `boolean`<br>
|
115 | Default: `false`
|
116 |
|
117 | Use [arithmetic coding](https://en.wikipedia.org/wiki/Arithmetic_coding).
|
118 |
|
119 | ##### dct
|
120 |
|
121 | Type: `string`<br>
|
122 | Default: `int`
|
123 |
|
124 | Set [DCT](https://en.wikipedia.org/wiki/Discrete_cosine_transform) method:
|
125 |
|
126 | - `int` Use integer DCT
|
127 | - `fast` Use fast integer DCT (less accurate)
|
128 | - `float` Use floating-point DCT
|
129 |
|
130 | ##### quantBaseline
|
131 |
|
132 | Type: `boolean`<br>
|
133 | Default: `false`
|
134 |
|
135 | Use 8-bit quantization table entries for baseline JPEG compatibility.
|
136 |
|
137 | ##### quantTable
|
138 |
|
139 | Type: `number`
|
140 |
|
141 | Use predefined quantization table.
|
142 |
|
143 | - `0` JPEG Annex K
|
144 | - `1` Flat
|
145 | - `2` Custom, tuned for MS-SSIM
|
146 | - `3` ImageMagick table by N. Robidoux
|
147 | - `4` Custom, tuned for PSNR-HVS
|
148 | - `5` Table from paper by Klein, Silverstein and Carney
|
149 |
|
150 | ##### smooth
|
151 |
|
152 | Type: `number`
|
153 |
|
154 | Set the strength of smooth dithered input. (1...100)
|
155 |
|
156 | ##### maxMemory
|
157 |
|
158 | Type: `number`
|
159 |
|
160 | Set the maximum memory to use in kilobytes.
|
161 |
|
162 | ##### sample
|
163 |
|
164 | Type: `string[]`
|
165 |
|
166 | Set component sampling factors. Each item should be in the format `HxV`, for example `2x1`.
|
167 |
|
168 | #### buffer
|
169 |
|
170 | Type: `buffer`
|
171 |
|
172 | Buffer to optimize.
|
173 |
|
174 |
|
175 | ## License
|
176 |
|
177 | MIT © [Imagemin](https://github.com/imagemin)
|