@depup/sharp-cli 5.2.0-depup.0 → 5.3.0-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierignore +2 -0
- package/.prettierrc +1 -0
- package/CHANGELOG.md +20 -8
- package/README.md +5 -5
- package/bin/cli.js +3 -3
- package/changes.json +5 -5
- package/cmd/channel-manipulation/bandbool.js +22 -16
- package/cmd/channel-manipulation/ensure-alpha.js +25 -17
- package/cmd/channel-manipulation/extract-channel.js +24 -16
- package/cmd/channel-manipulation/join-channel.js +17 -15
- package/cmd/channel-manipulation/remove-alpha.js +13 -10
- package/cmd/colour-manipulation/greyscale.js +17 -11
- package/cmd/colour-manipulation/pipeline-colourspace.js +26 -18
- package/cmd/colour-manipulation/tint.js +17 -14
- package/cmd/colour-manipulation/tocolourspace.js +23 -18
- package/cmd/compositing/composite.js +127 -99
- package/cmd/operations/affine.js +53 -45
- package/cmd/operations/blur.js +44 -36
- package/cmd/operations/boolean.js +23 -18
- package/cmd/operations/clahe.js +36 -31
- package/cmd/operations/convolve.js +51 -43
- package/cmd/operations/dilate.js +64 -0
- package/cmd/operations/erode.js +64 -0
- package/cmd/operations/flatten.js +24 -19
- package/cmd/operations/flip.js +12 -10
- package/cmd/operations/flop.js +12 -10
- package/cmd/operations/gamma.js +27 -20
- package/cmd/operations/linear.js +31 -24
- package/cmd/operations/median.js +19 -17
- package/cmd/operations/modulate.js +36 -26
- package/cmd/operations/negate.js +18 -15
- package/cmd/operations/normalise.js +27 -20
- package/cmd/operations/recomb.js +35 -27
- package/cmd/operations/rotate.js +32 -24
- package/cmd/operations/sharpen.js +45 -40
- package/cmd/operations/threshold.js +30 -24
- package/cmd/operations/unflatten.js +15 -11
- package/cmd/output.js +59 -51
- package/cmd/resizing/extend.js +56 -44
- package/cmd/resizing/extract.js +33 -28
- package/cmd/resizing/resize.js +80 -51
- package/cmd/resizing/trim.js +50 -31
- package/lib/cli.js +480 -366
- package/lib/constants.js +23 -15
- package/lib/convert.js +47 -52
- package/lib/index.js +23 -19
- package/lib/queue.js +8 -7
- package/package.json +12 -13
package/lib/cli.js
CHANGED
|
@@ -22,191 +22,205 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
// Strict mode.
|
|
25
|
-
|
|
25
|
+
"use strict";
|
|
26
26
|
|
|
27
27
|
// Package modules.
|
|
28
|
-
const pick = require(
|
|
29
|
-
const sharp = require(
|
|
30
|
-
const yargs = require(
|
|
28
|
+
const pick = require("lodash.pick");
|
|
29
|
+
const sharp = require("sharp");
|
|
30
|
+
const yargs = require("yargs");
|
|
31
31
|
|
|
32
32
|
// Local modules.
|
|
33
|
-
const constants = require(
|
|
34
|
-
const pkg = require(
|
|
35
|
-
const queue = require(
|
|
33
|
+
const constants = require("./constants");
|
|
34
|
+
const pkg = require("../package.json");
|
|
35
|
+
const queue = require("./queue");
|
|
36
36
|
|
|
37
37
|
// Configure.
|
|
38
|
-
const IS_TEXT_TERMINAL = process.stdin.isTTY
|
|
38
|
+
const IS_TEXT_TERMINAL = process.stdin.isTTY;
|
|
39
39
|
|
|
40
40
|
// Options.
|
|
41
|
-
const global =
|
|
42
|
-
const input =
|
|
43
|
-
const optimize =
|
|
44
|
-
const output =
|
|
41
|
+
const global = "Global Options";
|
|
42
|
+
const input = "Input Options";
|
|
43
|
+
const optimize = "Optimization Options";
|
|
44
|
+
const output = "Output Options";
|
|
45
45
|
|
|
46
46
|
const globalOptions = {
|
|
47
47
|
// @see https://sharp.pixelplumbing.com/api-constructor/
|
|
48
48
|
input: {
|
|
49
|
-
alias:
|
|
50
|
-
defaultDescription:
|
|
49
|
+
alias: "i",
|
|
50
|
+
defaultDescription: "stdin",
|
|
51
51
|
demand: IS_TEXT_TERMINAL,
|
|
52
|
-
desc:
|
|
52
|
+
desc: "Path to (an) image file(s)",
|
|
53
53
|
group: global,
|
|
54
|
-
implies:
|
|
55
|
-
type:
|
|
54
|
+
implies: "output",
|
|
55
|
+
type: "array",
|
|
56
56
|
},
|
|
57
57
|
|
|
58
58
|
// @see https://sharp.pixelplumbing.com/api-output/
|
|
59
59
|
output: {
|
|
60
|
-
alias:
|
|
61
|
-
defaultDescription:
|
|
60
|
+
alias: "o",
|
|
61
|
+
defaultDescription: "stdout",
|
|
62
62
|
demand: IS_TEXT_TERMINAL,
|
|
63
|
-
desc:
|
|
63
|
+
desc: "Directory or URI template to write the image files to",
|
|
64
64
|
group: global,
|
|
65
|
-
type:
|
|
65
|
+
type: "string",
|
|
66
66
|
},
|
|
67
67
|
|
|
68
68
|
// @see https://sharp.pixelplumbing.com/api-output#timeout
|
|
69
69
|
timeout: {
|
|
70
|
-
desc:
|
|
70
|
+
desc: "Number of seconds after which processing will be stopped",
|
|
71
71
|
group: global,
|
|
72
|
-
type:
|
|
73
|
-
}
|
|
74
|
-
}
|
|
72
|
+
type: "number",
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
75
|
|
|
76
76
|
// @see https://sharp.pixelplumbing.com/api-constructor
|
|
77
77
|
const inputOptions = {
|
|
78
78
|
animated: {
|
|
79
|
-
desc:
|
|
79
|
+
desc: "Read all frames/pages of an animated image",
|
|
80
80
|
group: input,
|
|
81
|
-
type:
|
|
81
|
+
type: "boolean",
|
|
82
82
|
},
|
|
83
83
|
autoOrient: {
|
|
84
|
-
desc:
|
|
84
|
+
desc: "Rotate/flip the image to match EXIF Orientation, if any",
|
|
85
85
|
group: input,
|
|
86
|
-
type:
|
|
86
|
+
type: "boolean",
|
|
87
87
|
},
|
|
88
88
|
failOn: {
|
|
89
89
|
choices: constants.FAIL_ON,
|
|
90
|
-
defaultDescription:
|
|
91
|
-
desc:
|
|
92
|
-
group: input
|
|
90
|
+
defaultDescription: "warning",
|
|
91
|
+
desc: "Level of sensitivity to invalid images",
|
|
92
|
+
group: input,
|
|
93
93
|
},
|
|
94
94
|
density: {
|
|
95
|
-
desc:
|
|
95
|
+
desc: "DPI for vector images",
|
|
96
96
|
defaultDescription: 72,
|
|
97
97
|
group: input,
|
|
98
|
-
type:
|
|
98
|
+
type: "number",
|
|
99
99
|
},
|
|
100
100
|
ignoreIcc: {
|
|
101
101
|
default: false,
|
|
102
|
-
desc:
|
|
102
|
+
desc: "Should the embedded ICC profile, if any, be ignored",
|
|
103
103
|
group: input,
|
|
104
|
-
type:
|
|
104
|
+
type: "boolean",
|
|
105
105
|
},
|
|
106
106
|
level: {
|
|
107
|
-
desc:
|
|
107
|
+
desc: "Level to extract from a multi-level input (OpenSlide), zero based",
|
|
108
108
|
defaultDescription: 0,
|
|
109
109
|
group: input,
|
|
110
|
-
type:
|
|
110
|
+
type: "number",
|
|
111
111
|
},
|
|
112
112
|
limitInputPixels: {
|
|
113
|
-
defaultDescription:
|
|
114
|
-
desc:
|
|
113
|
+
defaultDescription: 0x3fff * 0x3fff,
|
|
114
|
+
desc: "Do not process input images where the number of pixels (width x height) exceeds this limit",
|
|
115
115
|
group: input,
|
|
116
|
-
type:
|
|
116
|
+
type: "number",
|
|
117
117
|
},
|
|
118
118
|
page: {
|
|
119
119
|
defaultDescription: 0,
|
|
120
|
-
desc:
|
|
120
|
+
desc: "Page number to start extracting from for multi-page input",
|
|
121
121
|
group: input,
|
|
122
|
-
type:
|
|
122
|
+
type: "number",
|
|
123
123
|
},
|
|
124
124
|
pages: {
|
|
125
125
|
defaultDescription: 1,
|
|
126
|
-
desc:
|
|
126
|
+
desc: "Number of pages to extract for multi-page input",
|
|
127
127
|
group: input,
|
|
128
|
-
type:
|
|
128
|
+
type: "number",
|
|
129
129
|
},
|
|
130
130
|
pdfBackground: {
|
|
131
|
-
desc:
|
|
131
|
+
desc: "Background colour to use when PDF is partially transparent",
|
|
132
132
|
group: input,
|
|
133
|
-
type:
|
|
133
|
+
type: "string",
|
|
134
134
|
},
|
|
135
135
|
sequentialRead: {
|
|
136
136
|
default: false,
|
|
137
|
-
desc:
|
|
137
|
+
desc: "Use sequential rather than random access where possible",
|
|
138
138
|
group: input,
|
|
139
|
-
type:
|
|
139
|
+
type: "boolean",
|
|
140
140
|
},
|
|
141
141
|
subifd: {
|
|
142
142
|
defaultDescription: -1,
|
|
143
|
-
desc:
|
|
143
|
+
desc: "subIFD to extract for OME-TIFF",
|
|
144
144
|
group: input,
|
|
145
|
-
type:
|
|
145
|
+
type: "number",
|
|
146
146
|
},
|
|
147
147
|
unlimited: {
|
|
148
|
-
desc:
|
|
148
|
+
desc: "Remove safety features that help prevent memory exhaustion",
|
|
149
149
|
group: input,
|
|
150
|
-
type:
|
|
151
|
-
}
|
|
152
|
-
}
|
|
150
|
+
type: "boolean",
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
153
|
|
|
154
154
|
const outputOptions = {
|
|
155
|
+
// @see https://sharp.pixelplumbing.com/api-output#tiff
|
|
156
|
+
bigtiff: {
|
|
157
|
+
desc: "Use BigTIFF variant",
|
|
158
|
+
group: output,
|
|
159
|
+
type: "boolean",
|
|
160
|
+
},
|
|
161
|
+
|
|
155
162
|
// @see https://sharp.pixelplumbing.com/api-output#png
|
|
156
163
|
compressionLevel: {
|
|
157
|
-
alias:
|
|
158
|
-
desc:
|
|
164
|
+
alias: "c",
|
|
165
|
+
desc: "zlib compression level",
|
|
159
166
|
defaultDescription: 6,
|
|
160
167
|
group: output,
|
|
161
|
-
type:
|
|
168
|
+
type: "number",
|
|
162
169
|
},
|
|
163
170
|
|
|
164
171
|
// @see https://sharp.pixelplumbing.com/api-output#toformat
|
|
165
172
|
format: {
|
|
166
|
-
alias:
|
|
173
|
+
alias: "f",
|
|
167
174
|
choices: constants.FORMAT,
|
|
168
|
-
defaultDescription:
|
|
169
|
-
desc:
|
|
170
|
-
group: output
|
|
175
|
+
defaultDescription: "input",
|
|
176
|
+
desc: "Force output to a given format",
|
|
177
|
+
group: output,
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
// @see https://sharp.pixelplumbing.com/api-output#gif
|
|
181
|
+
keepDuplicateFrames: {
|
|
182
|
+
desc: "Keep duplicate frames in the output instead of combining them",
|
|
183
|
+
group: output,
|
|
184
|
+
type: "boolean",
|
|
171
185
|
},
|
|
172
186
|
|
|
173
187
|
// @see https://sharp.pixelplumbing.com/api-output#withmetadata
|
|
174
188
|
metadata: {
|
|
175
|
-
alias: [
|
|
176
|
-
desc:
|
|
189
|
+
alias: ["m", "withMetadata"],
|
|
190
|
+
desc: "Include all metadata (EXIF, XMP, IPTC) from the input image in the output image",
|
|
177
191
|
group: output,
|
|
178
|
-
type:
|
|
192
|
+
type: "boolean",
|
|
179
193
|
},
|
|
180
|
-
|
|
181
|
-
desc:
|
|
194
|
+
"metadata.density": {
|
|
195
|
+
desc: "Number of pixels per inch (DPI)",
|
|
182
196
|
group: output,
|
|
183
|
-
type:
|
|
197
|
+
type: "number",
|
|
184
198
|
},
|
|
185
|
-
|
|
186
|
-
defaultDescription:
|
|
187
|
-
desc:
|
|
199
|
+
"metadata.exif": {
|
|
200
|
+
defaultDescription: "{}",
|
|
201
|
+
desc: "Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data",
|
|
188
202
|
group: output,
|
|
189
|
-
type:
|
|
203
|
+
type: "object",
|
|
190
204
|
},
|
|
191
|
-
|
|
192
|
-
defaultDescription:
|
|
193
|
-
desc:
|
|
205
|
+
"metadata.icc": {
|
|
206
|
+
defaultDescription: "sRGB",
|
|
207
|
+
desc: "Filesystem path to output ICC profile",
|
|
194
208
|
group: output,
|
|
195
|
-
type:
|
|
209
|
+
type: "string",
|
|
196
210
|
},
|
|
197
|
-
|
|
198
|
-
desc:
|
|
211
|
+
"metadata.orientation": {
|
|
212
|
+
desc: "Used to update the EXIF Orientation tag",
|
|
199
213
|
group: output,
|
|
200
|
-
type:
|
|
214
|
+
type: "number",
|
|
201
215
|
},
|
|
202
216
|
|
|
203
217
|
// @see https://sharp.pixelplumbing.com/api-output#jpeg
|
|
204
218
|
// @see https://sharp.pixelplumbing.com/api-output#png
|
|
205
219
|
progressive: {
|
|
206
|
-
alias:
|
|
207
|
-
desc:
|
|
220
|
+
alias: "p",
|
|
221
|
+
desc: "Use progressive (interlace) scan",
|
|
208
222
|
group: output,
|
|
209
|
-
type:
|
|
223
|
+
type: "boolean",
|
|
210
224
|
},
|
|
211
225
|
|
|
212
226
|
// @see https://sharp.pixelplumbing.com/api-output#avif
|
|
@@ -214,79 +228,79 @@ const outputOptions = {
|
|
|
214
228
|
// @see https://sharp.pixelplumbing.com/api-output#tiff
|
|
215
229
|
// @see https://sharp.pixelplumbing.com/api-output#webp
|
|
216
230
|
quality: {
|
|
217
|
-
alias:
|
|
218
|
-
desc:
|
|
219
|
-
defaultDescription:
|
|
231
|
+
alias: "q",
|
|
232
|
+
desc: "Quality",
|
|
233
|
+
defaultDescription: "80",
|
|
220
234
|
group: output,
|
|
221
|
-
type:
|
|
222
|
-
}
|
|
223
|
-
}
|
|
235
|
+
type: "number",
|
|
236
|
+
},
|
|
237
|
+
};
|
|
224
238
|
|
|
225
239
|
const optimizationOptions = {
|
|
226
240
|
// @see https://sharp.pixelplumbing.com/api-output#png
|
|
227
241
|
adaptiveFiltering: {
|
|
228
|
-
desc:
|
|
242
|
+
desc: "Use adaptive row filtering",
|
|
229
243
|
group: optimize,
|
|
230
|
-
type:
|
|
244
|
+
type: "boolean",
|
|
231
245
|
},
|
|
232
246
|
|
|
233
247
|
// @see https://sharp.pixelplumbing.com/api-output#webp
|
|
234
248
|
alphaQuality: {
|
|
235
|
-
desc:
|
|
236
|
-
defaultDescription:
|
|
249
|
+
desc: "Quality of alpha layer",
|
|
250
|
+
defaultDescription: "80",
|
|
237
251
|
group: optimize,
|
|
238
|
-
type:
|
|
252
|
+
type: "number",
|
|
239
253
|
},
|
|
240
254
|
|
|
241
255
|
// @see https://sharp.pixelplumbing.com/api-output#tiff
|
|
242
256
|
bitdepth: {
|
|
243
257
|
choices: [1, 2, 4, 8],
|
|
244
258
|
defaultDescription: 8,
|
|
245
|
-
desc:
|
|
246
|
-
group: optimize
|
|
259
|
+
desc: "Reduce bitdepth to 1, 2, or 4 bit",
|
|
260
|
+
group: optimize,
|
|
247
261
|
},
|
|
248
262
|
|
|
249
263
|
// @see https://sharp.pixelplumbing.com/api-output#avif
|
|
250
264
|
// @see https://sharp.pixelplumbing.com/api-output#jpeg
|
|
251
265
|
chromaSubsampling: {
|
|
252
266
|
desc: 'Set to "4:4:4" to prevent chroma subsampling when quality <= 90',
|
|
253
|
-
defaultDescription:
|
|
267
|
+
defaultDescription: "4:4:4 (AVIF) / 4:2:0",
|
|
254
268
|
group: optimize,
|
|
255
|
-
type:
|
|
269
|
+
type: "string",
|
|
256
270
|
},
|
|
257
271
|
|
|
258
272
|
// @see https://sharp.pixelplumbing.com/api-output#gif
|
|
259
|
-
// @see https://sharp.
|
|
273
|
+
// @see https://sharp.pixelplumbing.com/api-output#png
|
|
260
274
|
colors: {
|
|
261
|
-
alias:
|
|
275
|
+
alias: "colours",
|
|
262
276
|
defaultDescription: 256,
|
|
263
|
-
desc:
|
|
277
|
+
desc: "Maximum number of palette entries",
|
|
264
278
|
group: optimize,
|
|
265
|
-
type:
|
|
279
|
+
type: "number",
|
|
266
280
|
},
|
|
267
281
|
|
|
268
282
|
// @see https://sharp.pixelplumbing.com/api-output#tiff
|
|
269
283
|
compression: {
|
|
270
284
|
choices: constants.TIFF_COMPRESSION,
|
|
271
|
-
default:
|
|
272
|
-
desc:
|
|
273
|
-
group: optimize
|
|
285
|
+
default: "jpeg",
|
|
286
|
+
desc: "Compression options",
|
|
287
|
+
group: optimize,
|
|
274
288
|
},
|
|
275
289
|
|
|
276
290
|
// @see https://sharp.pixelplumbing.com/api-output#gif
|
|
277
291
|
delay: {
|
|
278
|
-
desc:
|
|
292
|
+
desc: "Delay(s) between animation frames",
|
|
279
293
|
group: optimize,
|
|
280
|
-
type:
|
|
294
|
+
type: "number",
|
|
281
295
|
},
|
|
282
296
|
|
|
283
297
|
// @see https://sharp.pixelplumbing.com/api-output#gif
|
|
284
|
-
// @see https://sharp.
|
|
298
|
+
// @see https://sharp.pixelplumbing.com/api-output#png
|
|
285
299
|
dither: {
|
|
286
|
-
desc:
|
|
287
|
-
defaultDescription:
|
|
300
|
+
desc: "Level of Floyd-Steinberg error diffusion",
|
|
301
|
+
defaultDescription: "1.0",
|
|
288
302
|
group: optimize,
|
|
289
|
-
type:
|
|
303
|
+
type: "number",
|
|
290
304
|
},
|
|
291
305
|
|
|
292
306
|
// @see https://sharp.pixelplumbing.com/api-output#avif
|
|
@@ -295,326 +309,347 @@ const optimizationOptions = {
|
|
|
295
309
|
// @see https://sharp.pixelplumbing.com/api-output#png
|
|
296
310
|
// @see https://sharp.pixelplumbing.com/api-output#webp
|
|
297
311
|
effort: {
|
|
298
|
-
defaultDescription:
|
|
299
|
-
desc:
|
|
312
|
+
defaultDescription: "7 (GIF, PNG) / 4",
|
|
313
|
+
desc: "Level of CPU effort to reduce file size",
|
|
300
314
|
group: optimize,
|
|
301
|
-
type:
|
|
315
|
+
type: "number",
|
|
302
316
|
},
|
|
303
317
|
|
|
304
318
|
// @see https://sharp.pixelplumbing.com/api-output#heif
|
|
305
319
|
hbitdepth: {
|
|
306
320
|
choices: [8, 10, 12],
|
|
307
321
|
defaultDescription: 8,
|
|
308
|
-
desc:
|
|
309
|
-
group: optimize
|
|
322
|
+
desc: "Set bitdepth to 8, 10, or 12 bit",
|
|
323
|
+
group: optimize,
|
|
310
324
|
},
|
|
311
325
|
|
|
312
326
|
// @see https://sharp.pixelplumbing.com/api-output#heif
|
|
313
327
|
hcompression: {
|
|
314
328
|
choices: constants.HEIF_COMPRESSION,
|
|
315
|
-
default:
|
|
316
|
-
desc:
|
|
317
|
-
group: optimize
|
|
329
|
+
default: "av1",
|
|
330
|
+
desc: "Compression format",
|
|
331
|
+
group: optimize,
|
|
318
332
|
},
|
|
319
333
|
|
|
320
334
|
// @see https://sharp.pixelplumbing.com/api-output#gif
|
|
321
335
|
interFrameMaxError: {
|
|
322
|
-
desc:
|
|
336
|
+
desc: "Maximum inter-frame error for transparency",
|
|
323
337
|
group: optimize,
|
|
324
|
-
type:
|
|
338
|
+
type: "number",
|
|
325
339
|
},
|
|
326
340
|
|
|
327
341
|
// @see https://sharp.pixelplumbing.com/api-output#gif
|
|
328
342
|
interPaletteMaxError: {
|
|
329
|
-
desc:
|
|
343
|
+
desc: "Maximum inter-palette error for palette reuse",
|
|
330
344
|
group: optimize,
|
|
331
|
-
type:
|
|
345
|
+
type: "number",
|
|
332
346
|
},
|
|
333
347
|
|
|
334
348
|
// @see https://sharp.pixelplumbing.com/api-output#gif
|
|
335
349
|
loop: {
|
|
336
350
|
default: 0,
|
|
337
|
-
desc:
|
|
351
|
+
desc: "Number of animation iterations",
|
|
338
352
|
group: optimize,
|
|
339
|
-
type:
|
|
353
|
+
type: "number",
|
|
340
354
|
},
|
|
341
355
|
|
|
342
356
|
// @see https://sharp.pixelplumbing.com/api-output#avif
|
|
343
357
|
// @see https://sharp.pixelplumbing.com/api-output#webp
|
|
344
358
|
lossless: {
|
|
345
|
-
desc:
|
|
359
|
+
desc: "Use lossless compression mode",
|
|
346
360
|
group: optimize,
|
|
347
|
-
type:
|
|
361
|
+
type: "boolean",
|
|
348
362
|
},
|
|
349
363
|
|
|
350
364
|
// @see https://sharp.pixelplumbing.com/api-output#tiff
|
|
351
365
|
miniswhite: {
|
|
352
|
-
desc:
|
|
366
|
+
desc: "Write 1-bit images as miniswhite",
|
|
353
367
|
group: optimize,
|
|
354
|
-
type:
|
|
368
|
+
type: "boolean",
|
|
355
369
|
},
|
|
356
370
|
|
|
357
371
|
// @see https://sharp.pixelplumbing.com/api-output#webp
|
|
358
372
|
minSize: {
|
|
359
|
-
desc:
|
|
373
|
+
desc: "Prevent use of animation key frames to minimize file size",
|
|
360
374
|
group: optimize,
|
|
361
|
-
type:
|
|
375
|
+
type: "boolean",
|
|
362
376
|
},
|
|
363
377
|
|
|
364
378
|
// @see https://sharp.pixelplumbing.com/api-output#webp
|
|
365
379
|
mixed: {
|
|
366
|
-
desc:
|
|
380
|
+
desc: "Allow mixture of lossy and lossless animation frames",
|
|
367
381
|
group: optimize,
|
|
368
|
-
type:
|
|
382
|
+
type: "boolean",
|
|
369
383
|
},
|
|
370
384
|
|
|
371
385
|
// @see https://sharp.pixelplumbing.com/api-output#jpeg
|
|
372
386
|
mozjpeg: {
|
|
373
|
-
desc:
|
|
387
|
+
desc: "Use mozjpeg defaults",
|
|
374
388
|
group: optimize,
|
|
375
|
-
type:
|
|
389
|
+
type: "boolean",
|
|
376
390
|
},
|
|
377
391
|
|
|
378
392
|
// @see https://sharp.pixelplumbing.com/api-output#webp
|
|
379
393
|
nearLossless: {
|
|
380
|
-
desc:
|
|
394
|
+
desc: "Use near_lossless compression mode",
|
|
381
395
|
group: optimize,
|
|
382
|
-
type:
|
|
396
|
+
type: "boolean",
|
|
383
397
|
},
|
|
384
398
|
|
|
385
399
|
// @see https://sharp.pixelplumbing.com/api-output#jpeg
|
|
386
400
|
optimise: {
|
|
387
|
-
alias:
|
|
388
|
-
desc:
|
|
401
|
+
alias: "optimize",
|
|
402
|
+
desc: "Apply optimiseScans, overshootDeringing, and trellisQuantisation",
|
|
389
403
|
group: optimize,
|
|
390
|
-
type:
|
|
404
|
+
type: "boolean",
|
|
391
405
|
},
|
|
392
406
|
|
|
393
407
|
// @see https://sharp.pixelplumbing.com/api-output#jpeg
|
|
394
408
|
optimiseCoding: {
|
|
395
|
-
alias:
|
|
409
|
+
alias: "optimizeCoding",
|
|
396
410
|
default: true,
|
|
397
|
-
desc:
|
|
411
|
+
desc: "Optimise Huffman coding tables",
|
|
398
412
|
group: optimize,
|
|
399
|
-
type:
|
|
413
|
+
type: "boolean",
|
|
400
414
|
},
|
|
401
415
|
|
|
402
416
|
// @see https://sharp.pixelplumbing.com/api-output#jpeg
|
|
403
417
|
optimiseScans: {
|
|
404
|
-
alias:
|
|
405
|
-
desc:
|
|
418
|
+
alias: "optimizeScans",
|
|
419
|
+
desc: "Optimise progressive scans",
|
|
406
420
|
group: optimize,
|
|
407
|
-
implies:
|
|
408
|
-
type:
|
|
421
|
+
implies: "progressive",
|
|
422
|
+
type: "boolean",
|
|
409
423
|
},
|
|
410
424
|
|
|
411
425
|
// @see https://sharp.pixelplumbing.com/api-output#jpeg
|
|
412
426
|
overshootDeringing: {
|
|
413
|
-
desc:
|
|
427
|
+
desc: "Apply overshoot deringing",
|
|
414
428
|
group: optimize,
|
|
415
|
-
type:
|
|
429
|
+
type: "boolean",
|
|
416
430
|
},
|
|
417
431
|
|
|
418
|
-
// @see https://sharp.
|
|
432
|
+
// @see https://sharp.pixelplumbing.com/api-output#png
|
|
419
433
|
palette: {
|
|
420
|
-
desc:
|
|
434
|
+
desc: "Quantise to a palette-based image with alpha transparency support",
|
|
421
435
|
group: optimize,
|
|
422
|
-
type:
|
|
436
|
+
type: "boolean",
|
|
423
437
|
},
|
|
424
438
|
|
|
425
439
|
// @see https://sharp.pixelplumbing.com/api-output#tiff
|
|
426
440
|
predictor: {
|
|
427
441
|
choices: constants.TIFF_PREDICTOR,
|
|
428
|
-
default:
|
|
429
|
-
desc:
|
|
430
|
-
group: optimize
|
|
442
|
+
default: "horizontal",
|
|
443
|
+
desc: "Compression predictor",
|
|
444
|
+
group: optimize,
|
|
431
445
|
},
|
|
432
446
|
|
|
433
447
|
// @see https://sharp.pixelplumbing.com/api-output#webp
|
|
434
448
|
preset: {
|
|
435
449
|
choices: constants.PRESETS,
|
|
436
|
-
default:
|
|
437
|
-
desc:
|
|
438
|
-
group: optimize
|
|
450
|
+
default: "default",
|
|
451
|
+
desc: "Named preset for preprocessing/filtering",
|
|
452
|
+
group: optimize,
|
|
439
453
|
},
|
|
440
454
|
|
|
441
455
|
// @see https://sharp.pixelplumbing.com/api-output#tiff
|
|
442
456
|
pyramid: {
|
|
443
|
-
desc:
|
|
457
|
+
desc: "Write an image pyramid",
|
|
444
458
|
group: optimize,
|
|
445
|
-
type:
|
|
459
|
+
type: "boolean",
|
|
446
460
|
},
|
|
447
461
|
|
|
448
462
|
// @see https://sharp.pixelplumbing.com/api-output#jpeg
|
|
449
463
|
quantisationTable: {
|
|
450
|
-
alias:
|
|
451
|
-
defaultDescription:
|
|
452
|
-
desc:
|
|
464
|
+
alias: "quantizationTable",
|
|
465
|
+
defaultDescription: "0",
|
|
466
|
+
desc: "Quantization table to use",
|
|
453
467
|
group: optimize,
|
|
454
|
-
type:
|
|
468
|
+
type: "number",
|
|
455
469
|
},
|
|
456
470
|
|
|
457
471
|
// @see https://sharp.pixelplumbing.com/api-output#gif
|
|
458
472
|
reuse: {
|
|
459
|
-
alias: [
|
|
460
|
-
desc:
|
|
473
|
+
alias: ["reoptimise", "reoptimize"],
|
|
474
|
+
desc: "Always generate new palettes (slow)",
|
|
461
475
|
group: optimize,
|
|
462
|
-
type:
|
|
476
|
+
type: "boolean",
|
|
463
477
|
},
|
|
464
478
|
|
|
465
479
|
// @see https://sharp.pixelplumbing.com/api-output
|
|
466
480
|
resolutionUnit: {
|
|
467
481
|
choices: constants.RESOLUTION_UNIT,
|
|
468
|
-
defaultDescription:
|
|
469
|
-
desc:
|
|
470
|
-
group: optimize
|
|
482
|
+
defaultDescription: "inch",
|
|
483
|
+
desc: "Resolution unit",
|
|
484
|
+
group: optimize,
|
|
471
485
|
},
|
|
472
486
|
|
|
473
487
|
// @see https://sharp.pixelplumbing.com/api-output#webp
|
|
474
488
|
smartDeblock: {
|
|
475
|
-
desc:
|
|
489
|
+
desc: "Auto-adjust the deblocking filter, can improve low contrast edges",
|
|
476
490
|
group: optimize,
|
|
477
|
-
type:
|
|
491
|
+
type: "boolean",
|
|
478
492
|
},
|
|
479
493
|
|
|
480
494
|
// @see https://sharp.pixelplumbing.com/api-output#webp
|
|
481
495
|
smartSubsample: {
|
|
482
|
-
desc:
|
|
496
|
+
desc: "High quality chroma subsampling",
|
|
483
497
|
group: optimize,
|
|
484
|
-
type:
|
|
498
|
+
type: "boolean",
|
|
485
499
|
},
|
|
486
500
|
|
|
487
501
|
// @see https://sharp.pixelplumbing.com/api-output#tile
|
|
488
502
|
tileBackground: {
|
|
489
|
-
defaultDescription:
|
|
490
|
-
desc:
|
|
503
|
+
defaultDescription: "rgba(255, 255, 255, 1)",
|
|
504
|
+
desc: "Background colour, parsed by the color module",
|
|
491
505
|
group: optimize,
|
|
492
|
-
type:
|
|
506
|
+
type: "string",
|
|
493
507
|
},
|
|
494
508
|
|
|
495
509
|
// @see https://sharp.pixelplumbing.com/api-output#tiff
|
|
496
510
|
tileHeight: {
|
|
497
|
-
desc:
|
|
511
|
+
desc: "Vertical tile size",
|
|
498
512
|
group: optimize,
|
|
499
|
-
type:
|
|
513
|
+
type: "number",
|
|
500
514
|
},
|
|
501
515
|
|
|
502
516
|
// @see https://sharp.pixelplumbing.com/api-output#tiff
|
|
503
517
|
tileWidth: {
|
|
504
|
-
desc:
|
|
518
|
+
desc: "Horizontal tile size",
|
|
505
519
|
group: optimize,
|
|
506
|
-
type:
|
|
520
|
+
type: "number",
|
|
507
521
|
},
|
|
508
522
|
|
|
509
523
|
// @see https://sharp.pixelplumbing.com/api-output#jpeg
|
|
510
524
|
trellisQuantisation: {
|
|
511
|
-
desc:
|
|
525
|
+
desc: "Apply trellis quantisation",
|
|
512
526
|
group: optimize,
|
|
513
|
-
type:
|
|
527
|
+
type: "boolean",
|
|
514
528
|
},
|
|
515
529
|
|
|
516
530
|
// @see https://sharp.pixelplumbing.com/api-output#tiff
|
|
517
531
|
xres: {
|
|
518
|
-
defaultDescription:
|
|
519
|
-
desc:
|
|
532
|
+
defaultDescription: "1.0",
|
|
533
|
+
desc: "Horizontal resolution",
|
|
520
534
|
group: optimize,
|
|
521
|
-
type:
|
|
535
|
+
type: "number",
|
|
522
536
|
},
|
|
523
537
|
|
|
524
538
|
// @see https://sharp.pixelplumbing.com/api-output#tiff
|
|
525
539
|
yres: {
|
|
526
|
-
defaultDescription:
|
|
527
|
-
desc:
|
|
540
|
+
defaultDescription: "1.0",
|
|
541
|
+
desc: "Vertical resolution",
|
|
528
542
|
group: optimize,
|
|
529
|
-
type:
|
|
530
|
-
}
|
|
531
|
-
}
|
|
543
|
+
type: "number",
|
|
544
|
+
},
|
|
545
|
+
};
|
|
532
546
|
|
|
533
547
|
const options = {
|
|
534
548
|
...globalOptions,
|
|
535
549
|
...inputOptions,
|
|
536
550
|
...outputOptions,
|
|
537
|
-
...optimizationOptions
|
|
538
|
-
}
|
|
551
|
+
...optimizationOptions,
|
|
552
|
+
};
|
|
539
553
|
|
|
540
554
|
// Configure.
|
|
541
555
|
const cli = yargs
|
|
542
|
-
.parserConfiguration({
|
|
556
|
+
.parserConfiguration({ "populate--": true })
|
|
543
557
|
.strict()
|
|
544
|
-
.usage(
|
|
558
|
+
.usage("$0 <options> [command..]")
|
|
545
559
|
.options(options)
|
|
546
|
-
.example(
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
.example(
|
|
551
|
-
|
|
560
|
+
.example(
|
|
561
|
+
"$0 -i ./input.jpg -o ./out resize 300 200",
|
|
562
|
+
"out/input.jpg will be a 300 pixels wide and 200 pixels high image containing a scaled and cropped version of input.jpg",
|
|
563
|
+
)
|
|
564
|
+
.example(
|
|
565
|
+
'$0 -i ./input.jpg -o ./out -mq90 rotate 180 -- resize 300 -- flatten "#ff6600" -- composite ./overlay.png --gravity southeast -- sharpen',
|
|
566
|
+
"out/input.jpg will be an upside down, 300px wide, alpha channel flattened onto orange background, composited with overlay.png with SE gravity, sharpened, with metadata, 90% quality version of input.jpg",
|
|
567
|
+
)
|
|
568
|
+
.example(
|
|
569
|
+
"$0 -i ./input.jpg -o ./out --metadata",
|
|
570
|
+
"Include all metadata in the output image",
|
|
571
|
+
)
|
|
572
|
+
.example(
|
|
573
|
+
'$0 -i ./input.jpg -o ./out --metadata.exif.IFD0.Copyright "Wernham Hogg"',
|
|
574
|
+
'Set "IFD0-Copyright" in output EXIF metadata',
|
|
575
|
+
)
|
|
576
|
+
.example(
|
|
577
|
+
"$0 -i ./input.jpg -o ./out --metadata.density 96",
|
|
578
|
+
"Set output metadata to 96 DPI",
|
|
579
|
+
)
|
|
580
|
+
.epilog(
|
|
581
|
+
"For more information on available options, please visit https://sharp.pixelplumbing.com/",
|
|
582
|
+
)
|
|
552
583
|
.showHelpOnFail(false)
|
|
553
584
|
.wrap(100)
|
|
554
585
|
|
|
555
586
|
// Built-in options.
|
|
556
|
-
.help()
|
|
557
|
-
.
|
|
558
|
-
.
|
|
587
|
+
.help()
|
|
588
|
+
.alias("help", "h")
|
|
589
|
+
.version(pkg.version)
|
|
590
|
+
.alias("version", "v")
|
|
591
|
+
.group(["help", "version"], "Misc. Options")
|
|
559
592
|
|
|
560
593
|
// Commands.
|
|
561
594
|
// Avoid `yargs.commandDir()` as it uses insertion order, not alphabetical.
|
|
562
|
-
.command(require(
|
|
563
|
-
.command(require(
|
|
564
|
-
.command(require(
|
|
565
|
-
.command(require(
|
|
566
|
-
.command(require(
|
|
567
|
-
.command(require(
|
|
568
|
-
.command(require(
|
|
569
|
-
.command(require(
|
|
570
|
-
.command(require(
|
|
571
|
-
.command(require(
|
|
572
|
-
.command(require(
|
|
573
|
-
.command(require(
|
|
574
|
-
.command(require(
|
|
575
|
-
.command(require(
|
|
576
|
-
.command(require(
|
|
577
|
-
.command(require(
|
|
578
|
-
.command(require(
|
|
579
|
-
.command(require(
|
|
580
|
-
.command(require(
|
|
581
|
-
.command(require(
|
|
582
|
-
.command(require(
|
|
583
|
-
.command(require(
|
|
584
|
-
.command(require(
|
|
585
|
-
.command(require(
|
|
586
|
-
.command(require(
|
|
587
|
-
.command(require(
|
|
588
|
-
.command(require(
|
|
589
|
-
.command(require(
|
|
590
|
-
.command(require(
|
|
591
|
-
.command(require(
|
|
592
|
-
.command(require(
|
|
593
|
-
.command(require(
|
|
594
|
-
.command(require(
|
|
595
|
-
.command(require(
|
|
595
|
+
.command(require("../cmd/operations/affine"))
|
|
596
|
+
.command(require("../cmd/channel-manipulation/bandbool"))
|
|
597
|
+
.command(require("../cmd/operations/blur"))
|
|
598
|
+
.command(require("../cmd/operations/boolean"))
|
|
599
|
+
.command(require("../cmd/operations/clahe"))
|
|
600
|
+
.command(require("../cmd/compositing/composite"))
|
|
601
|
+
.command(require("../cmd/operations/convolve"))
|
|
602
|
+
.command(require("../cmd/operations/dilate"))
|
|
603
|
+
.command(require("../cmd/channel-manipulation/ensure-alpha"))
|
|
604
|
+
.command(require("../cmd/operations/erode"))
|
|
605
|
+
.command(require("../cmd/resizing/extend"))
|
|
606
|
+
.command(require("../cmd/resizing/extract"))
|
|
607
|
+
.command(require("../cmd/channel-manipulation/extract-channel"))
|
|
608
|
+
.command(require("../cmd/operations/flatten"))
|
|
609
|
+
.command(require("../cmd/operations/flip"))
|
|
610
|
+
.command(require("../cmd/operations/flop"))
|
|
611
|
+
.command(require("../cmd/operations/gamma"))
|
|
612
|
+
.command(require("../cmd/colour-manipulation/greyscale"))
|
|
613
|
+
.command(require("../cmd/channel-manipulation/join-channel"))
|
|
614
|
+
.command(require("../cmd/operations/linear"))
|
|
615
|
+
.command(require("../cmd/operations/median"))
|
|
616
|
+
.command(require("../cmd/operations/modulate"))
|
|
617
|
+
.command(require("../cmd/operations/negate"))
|
|
618
|
+
.command(require("../cmd/operations/normalise"))
|
|
619
|
+
.command(require("../cmd/colour-manipulation/pipeline-colourspace"))
|
|
620
|
+
.command(require("../cmd/operations/recomb"))
|
|
621
|
+
.command(require("../cmd/channel-manipulation/remove-alpha"))
|
|
622
|
+
.command(require("../cmd/resizing/resize"))
|
|
623
|
+
.command(require("../cmd/operations/rotate"))
|
|
624
|
+
.command(require("../cmd/operations/sharpen"))
|
|
625
|
+
.command(require("../cmd/operations/threshold"))
|
|
626
|
+
.command(require("../cmd/colour-manipulation/tint"))
|
|
627
|
+
.command(require("../cmd/output"))
|
|
628
|
+
.command(require("../cmd/colour-manipulation/tocolourspace"))
|
|
629
|
+
.command(require("../cmd/resizing/trim"))
|
|
630
|
+
.command(require("../cmd/operations/unflatten"));
|
|
596
631
|
|
|
597
632
|
// Helpers.
|
|
598
|
-
const originalParse = cli.parse.bind(cli)
|
|
633
|
+
const originalParse = cli.parse.bind(cli);
|
|
599
634
|
const promisifiedParse = (...args) => {
|
|
600
635
|
return new Promise((resolve, reject) => {
|
|
601
636
|
originalParse(...args, (err, argv, output) => {
|
|
602
637
|
if (err) {
|
|
603
|
-
reject(err)
|
|
638
|
+
reject(err);
|
|
604
639
|
}
|
|
605
640
|
if (argv.v || argv.help) {
|
|
606
|
-
reject(output)
|
|
641
|
+
reject(output);
|
|
607
642
|
}
|
|
608
|
-
resolve(argv)
|
|
609
|
-
})
|
|
610
|
-
})
|
|
611
|
-
}
|
|
643
|
+
resolve(argv);
|
|
644
|
+
});
|
|
645
|
+
});
|
|
646
|
+
};
|
|
612
647
|
|
|
613
648
|
// Exports.
|
|
614
|
-
module.exports = cli
|
|
615
|
-
module.exports.inputOptions = Object.keys(inputOptions)
|
|
616
|
-
module.exports.parse = function recursiveParse
|
|
617
|
-
return promisifiedParse(args, context).then(argv => {
|
|
649
|
+
module.exports = cli;
|
|
650
|
+
module.exports.inputOptions = Object.keys(inputOptions);
|
|
651
|
+
module.exports.parse = function recursiveParse(args, context = {}) {
|
|
652
|
+
return promisifiedParse(args, context).then((argv) => {
|
|
618
653
|
// Handle arguments.
|
|
619
654
|
// NOTE Use queue.unshift to apply global options first.
|
|
620
655
|
|
|
@@ -623,74 +658,115 @@ module.exports.parse = function recursiveParse (args, context = {}) {
|
|
|
623
658
|
// Require at least one input file.
|
|
624
659
|
// NOTE: check here b/c https://github.com/yargs/yargs/issues/403
|
|
625
660
|
if (argv.input && argv.input.length === 0) {
|
|
626
|
-
throw new Error(
|
|
661
|
+
throw new Error("Not enough arguments following: i, input");
|
|
627
662
|
}
|
|
628
663
|
|
|
629
664
|
// @see https://sharp.pixelplumbing.com/api-output#timeout
|
|
630
665
|
if (argv.timeout) {
|
|
631
|
-
queue.unshift([
|
|
666
|
+
queue.unshift([
|
|
667
|
+
"timeout",
|
|
668
|
+
(sharp) => sharp.timeout({ seconds: argv.timeout }),
|
|
669
|
+
]);
|
|
632
670
|
}
|
|
633
671
|
|
|
634
672
|
// Output options.
|
|
635
673
|
|
|
636
674
|
// @see https://sharp.pixelplumbing.com/api-output#toformat
|
|
637
675
|
if (argv.format) {
|
|
638
|
-
queue.unshift([
|
|
676
|
+
queue.unshift([
|
|
677
|
+
"format",
|
|
678
|
+
(sharp) =>
|
|
679
|
+
sharp.toFormat(argv.format, { compression: argv.hcompression }),
|
|
680
|
+
]);
|
|
639
681
|
}
|
|
640
682
|
|
|
641
683
|
// @see https://sharp.pixelplumbing.com/api-output#withmetadata
|
|
642
684
|
if (argv.metadata) {
|
|
643
|
-
queue.unshift([
|
|
685
|
+
queue.unshift([
|
|
686
|
+
"withMetadata",
|
|
687
|
+
(sharp) => sharp.withMetadata(argv.metadata),
|
|
688
|
+
]);
|
|
644
689
|
}
|
|
645
690
|
|
|
646
691
|
// @see https://sharp.pixelplumbing.com/api-output#heif
|
|
647
|
-
const { heif } = sharp.format
|
|
648
|
-
if (
|
|
692
|
+
const { heif } = sharp.format;
|
|
693
|
+
if (
|
|
694
|
+
argv.hcompression !== optimizationOptions.hcompression.default || // HEIF-specific.
|
|
649
695
|
// Ensure libheif is installed before applying generic options.
|
|
650
|
-
(heif.input &&
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
696
|
+
(heif.input &&
|
|
697
|
+
heif.input.file &&
|
|
698
|
+
(argv.effort !== undefined ||
|
|
699
|
+
argv.hbitdepth ||
|
|
700
|
+
argv.lossless ||
|
|
701
|
+
argv.quality))
|
|
702
|
+
) {
|
|
703
|
+
queue.unshift([
|
|
704
|
+
"heif",
|
|
705
|
+
(sharp) => {
|
|
706
|
+
return sharp.heif({
|
|
707
|
+
bitdepth: argv.hbitdepth,
|
|
708
|
+
compression: argv.hcompression,
|
|
709
|
+
effort: argv.effort,
|
|
710
|
+
force: false,
|
|
711
|
+
lossless: argv.lossless,
|
|
712
|
+
quality: argv.quality,
|
|
713
|
+
});
|
|
714
|
+
},
|
|
715
|
+
]);
|
|
662
716
|
}
|
|
663
717
|
|
|
664
718
|
// @see https://sharp.pixelplumbing.com/api-output#avif
|
|
665
|
-
if (
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
719
|
+
if (
|
|
720
|
+
argv.chromaSubsampling ||
|
|
721
|
+
argv.effort !== undefined ||
|
|
722
|
+
argv.lossless ||
|
|
723
|
+
argv.quality
|
|
724
|
+
) {
|
|
725
|
+
queue.unshift([
|
|
726
|
+
"avif",
|
|
727
|
+
(sharp) => {
|
|
728
|
+
return sharp.avif({
|
|
729
|
+
chromaSubsampling: argv.chromaSubsampling,
|
|
730
|
+
effort: argv.effort,
|
|
731
|
+
force: false,
|
|
732
|
+
lossless: argv.lossless,
|
|
733
|
+
quality: argv.quality,
|
|
734
|
+
});
|
|
735
|
+
},
|
|
736
|
+
]);
|
|
675
737
|
}
|
|
676
738
|
|
|
677
739
|
// @see https://sharp.pixelplumbing.com/api-output#gif
|
|
678
|
-
if (
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
740
|
+
if (
|
|
741
|
+
argv.colors ||
|
|
742
|
+
argv.effort !== undefined ||
|
|
743
|
+
argv.dither !== undefined ||
|
|
744
|
+
argv.interFrameMaxError ||
|
|
745
|
+
argv.interPaletteMaxError ||
|
|
746
|
+
argv.keepDuplicateFrames ||
|
|
747
|
+
argv.loop ||
|
|
748
|
+
argv.delay !== undefined ||
|
|
749
|
+
argv.progressive ||
|
|
750
|
+
argv.reuse
|
|
751
|
+
) {
|
|
752
|
+
queue.unshift([
|
|
753
|
+
"gif",
|
|
754
|
+
(sharp) => {
|
|
755
|
+
return sharp.gif({
|
|
756
|
+
colors: argv.colors,
|
|
757
|
+
force: false,
|
|
758
|
+
effort: argv.effort,
|
|
759
|
+
dither: argv.dither,
|
|
760
|
+
interFrameMaxError: argv.interFrameMaxError,
|
|
761
|
+
interPaletteMaxError: argv.interPaletteMaxError,
|
|
762
|
+
keepDuplicateFrames: argv.keepDuplicateFrames,
|
|
763
|
+
loop: argv.loop,
|
|
764
|
+
delay: argv.delay,
|
|
765
|
+
progressive: argv.progressive,
|
|
766
|
+
reuse: argv.reuse,
|
|
767
|
+
});
|
|
768
|
+
},
|
|
769
|
+
]);
|
|
694
770
|
}
|
|
695
771
|
|
|
696
772
|
// @see https://sharp.pixelplumbing.com/api-output#jpeg
|
|
@@ -706,95 +782,133 @@ module.exports.parse = function recursiveParse (args, context = {}) {
|
|
|
706
782
|
argv.quality ||
|
|
707
783
|
argv.trellisQuantisation
|
|
708
784
|
) {
|
|
709
|
-
queue.unshift([
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
785
|
+
queue.unshift([
|
|
786
|
+
"jpeg",
|
|
787
|
+
(sharp) => {
|
|
788
|
+
return sharp.jpeg({
|
|
789
|
+
chromaSubsampling: argv.chromaSubsampling,
|
|
790
|
+
force: false,
|
|
791
|
+
mozjpeg: argv.mozjpeg,
|
|
792
|
+
optimiseCoding: argv.optimiseCoding,
|
|
793
|
+
optimiseScans: argv.optimise || argv.optimiseScans,
|
|
794
|
+
overshootDeringing: argv.optimise || argv.overshootDeringing,
|
|
795
|
+
progressive: argv.progressive,
|
|
796
|
+
quality: argv.quality,
|
|
797
|
+
quantisationTable: argv.quantisationTable,
|
|
798
|
+
trellisQuantisation: argv.optimise || argv.trellisQuantisation,
|
|
799
|
+
});
|
|
800
|
+
},
|
|
801
|
+
]);
|
|
723
802
|
}
|
|
724
803
|
|
|
725
804
|
// @see https://sharp.pixelplumbing.com/api-output#png
|
|
726
|
-
if (
|
|
727
|
-
argv.
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
805
|
+
if (
|
|
806
|
+
argv.adaptiveFiltering ||
|
|
807
|
+
argv.colors ||
|
|
808
|
+
argv.compressionLevel !== undefined ||
|
|
809
|
+
argv.dither !== undefined ||
|
|
810
|
+
argv.effort ||
|
|
811
|
+
argv.palette ||
|
|
812
|
+
argv.progressive
|
|
813
|
+
) {
|
|
814
|
+
queue.unshift([
|
|
815
|
+
"png",
|
|
816
|
+
(sharp) => {
|
|
817
|
+
return sharp.png({
|
|
818
|
+
adaptiveFiltering: argv.adaptiveFiltering,
|
|
819
|
+
colors: argv.colors,
|
|
820
|
+
compressionLevel: argv.compressionLevel,
|
|
821
|
+
dither: argv.dither,
|
|
822
|
+
effort: argv.effort,
|
|
823
|
+
force: false,
|
|
824
|
+
palette: argv.palette,
|
|
825
|
+
progressive: argv.progressive,
|
|
826
|
+
});
|
|
827
|
+
},
|
|
828
|
+
]);
|
|
740
829
|
}
|
|
741
830
|
|
|
742
831
|
// @see https://sharp.pixelplumbing.com/api-output#tiff
|
|
743
|
-
if (
|
|
832
|
+
if (
|
|
833
|
+
argv.bigtiff ||
|
|
834
|
+
argv.bitdepth ||
|
|
744
835
|
argv.compression !== optimizationOptions.compression.default ||
|
|
745
836
|
argv.predictor !== optimizationOptions.predictor.default ||
|
|
746
|
-
argv.miniswhite ||
|
|
747
|
-
argv.
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
837
|
+
argv.miniswhite ||
|
|
838
|
+
argv.pyramid ||
|
|
839
|
+
argv.quality ||
|
|
840
|
+
argv.resolutionUnit ||
|
|
841
|
+
argv.tileBackground ||
|
|
842
|
+
argv.tileHeight ||
|
|
843
|
+
argv.tileWidth ||
|
|
844
|
+
argv.xres ||
|
|
845
|
+
argv.yres
|
|
846
|
+
) {
|
|
847
|
+
queue.unshift([
|
|
848
|
+
"tiff",
|
|
849
|
+
(sharp) => {
|
|
850
|
+
return sharp.tiff({
|
|
851
|
+
background: argv.tileBackground,
|
|
852
|
+
bigtiff: argv.bigtiff,
|
|
853
|
+
bitdepth: argv.bitdepth,
|
|
854
|
+
compression: argv.compression,
|
|
855
|
+
force: false,
|
|
856
|
+
miniswhite: argv.miniswhite,
|
|
857
|
+
predictor: argv.predictor,
|
|
858
|
+
pyramid: argv.pyramid,
|
|
859
|
+
quality: argv.quality,
|
|
860
|
+
resolutionUnit: argv.resolutionUnit,
|
|
861
|
+
tile: argv.tileWidth !== undefined || argv.tileHeight !== undefined,
|
|
862
|
+
tileHeight: argv.tileHeight || argv.tileWidth,
|
|
863
|
+
tileWidth: argv.tileWidth || argv.tileHeight,
|
|
864
|
+
xres: argv.xres,
|
|
865
|
+
yres: argv.yres,
|
|
866
|
+
});
|
|
867
|
+
},
|
|
868
|
+
]);
|
|
766
869
|
}
|
|
767
870
|
|
|
768
871
|
// @see https://sharp.pixelplumbing.com/api-output#webp
|
|
769
|
-
if (
|
|
770
|
-
argv.
|
|
771
|
-
argv.
|
|
772
|
-
argv.
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
872
|
+
if (
|
|
873
|
+
argv.alphaQuality ||
|
|
874
|
+
argv.quality ||
|
|
875
|
+
argv.lossless ||
|
|
876
|
+
argv.minSize ||
|
|
877
|
+
argv.mixed ||
|
|
878
|
+
argv.nearLossless ||
|
|
879
|
+
argv.effort !== undefined ||
|
|
880
|
+
argv.preset !== optimizationOptions.preset.default ||
|
|
881
|
+
argv.smartDeblock ||
|
|
882
|
+
argv.smartSubsample
|
|
883
|
+
) {
|
|
884
|
+
queue.unshift([
|
|
885
|
+
"webp",
|
|
886
|
+
(sharp) => {
|
|
887
|
+
return sharp.webp({
|
|
888
|
+
alphaQuality: argv.alphaQuality,
|
|
889
|
+
effort: argv.effort,
|
|
890
|
+
force: false,
|
|
891
|
+
lossless: argv.lossless,
|
|
892
|
+
minSize: argv.minSize,
|
|
893
|
+
mixed: argv.mixed,
|
|
894
|
+
nearLossless: argv.nearLossless,
|
|
895
|
+
preset: argv.preset,
|
|
896
|
+
quality: argv.quality,
|
|
897
|
+
smartDeblock: argv.smartDeblock,
|
|
898
|
+
smartSubsample: argv.smartSubsample,
|
|
899
|
+
});
|
|
900
|
+
},
|
|
901
|
+
]);
|
|
788
902
|
}
|
|
789
903
|
|
|
790
904
|
// Invoke with remaining arguments (if any).
|
|
791
|
-
const {
|
|
905
|
+
const { "--": remainingargv = [] } = argv;
|
|
792
906
|
if (remainingargv.length > 0) {
|
|
793
907
|
return recursiveParse(remainingargv, {
|
|
794
908
|
...context,
|
|
795
|
-
...pick(argv, Object.keys(options)) // Retain options.
|
|
796
|
-
})
|
|
909
|
+
...pick(argv, Object.keys(options)), // Retain options.
|
|
910
|
+
});
|
|
797
911
|
}
|
|
798
|
-
return argv
|
|
799
|
-
})
|
|
800
|
-
}
|
|
912
|
+
return argv;
|
|
913
|
+
});
|
|
914
|
+
};
|