@depup/sharp-cli 5.2.0-depup.0 → 6.0.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/.github/workflows/ci.yml +30 -0
- package/.prettierignore +2 -0
- package/.prettierrc +1 -0
- package/CHANGELOG.md +40 -8
- package/README.md +6 -9
- package/bin/cli.js +5 -5
- package/changes.json +5 -17
- package/cmd/channel-manipulation/bandbool.js +24 -19
- package/cmd/channel-manipulation/ensure-alpha.js +27 -22
- package/cmd/channel-manipulation/extract-channel.js +23 -19
- package/cmd/channel-manipulation/join-channel.js +19 -20
- package/cmd/channel-manipulation/remove-alpha.js +12 -15
- package/cmd/colour-manipulation/greyscale.js +16 -16
- package/cmd/colour-manipulation/pipeline-colourspace.js +26 -22
- package/cmd/colour-manipulation/tint.js +17 -19
- package/cmd/colour-manipulation/tocolourspace.js +22 -21
- package/cmd/compositing/composite.js +133 -102
- package/cmd/operations/affine.js +57 -51
- package/cmd/operations/blur.js +44 -41
- package/cmd/operations/boolean.js +22 -21
- package/cmd/operations/clahe.js +37 -37
- package/cmd/operations/convolve.js +52 -48
- package/cmd/operations/dilate.js +58 -0
- package/cmd/operations/erode.js +58 -0
- package/cmd/operations/flatten.js +23 -24
- package/cmd/operations/flip.js +12 -15
- package/cmd/operations/flop.js +12 -15
- package/cmd/operations/gamma.js +26 -25
- package/cmd/operations/linear.js +30 -29
- package/cmd/operations/median.js +18 -22
- package/cmd/operations/modulate.js +42 -31
- package/cmd/operations/negate.js +17 -20
- package/cmd/operations/normalise.js +28 -25
- package/cmd/operations/recomb.js +34 -32
- package/cmd/operations/rotate.js +31 -29
- package/cmd/operations/sharpen.js +49 -45
- package/cmd/operations/threshold.js +29 -29
- package/cmd/operations/unflatten.js +14 -16
- package/cmd/output.js +61 -56
- package/cmd/resizing/extend.js +55 -49
- package/cmd/resizing/extract.js +32 -33
- package/cmd/resizing/resize.js +79 -56
- package/cmd/resizing/trim.js +59 -36
- package/{lib/queue.js → eslint.config.mjs} +21 -17
- package/lib/cli.js +637 -383
- package/lib/constants.js +24 -18
- package/lib/convert.js +106 -73
- package/lib/index.js +56 -23
- package/lib/utils.js +50 -0
- package/package.json +27 -37
|
@@ -23,41 +23,42 @@
|
|
|
23
23
|
|
|
24
24
|
// @see https://sharp.pixelplumbing.com/api-colour#tocolourspace
|
|
25
25
|
|
|
26
|
-
// Strict mode.
|
|
27
|
-
'use strict'
|
|
28
|
-
|
|
29
26
|
// Local modules.
|
|
30
|
-
|
|
31
|
-
const queue = require('../../lib/queue')
|
|
27
|
+
import constants from "../../lib/constants.js";
|
|
32
28
|
|
|
33
29
|
// Configure.
|
|
34
30
|
const positionals = {
|
|
35
31
|
colourspace: {
|
|
36
32
|
choices: constants.COLOURSPACE,
|
|
37
|
-
default:
|
|
38
|
-
desc:
|
|
39
|
-
}
|
|
40
|
-
}
|
|
33
|
+
default: "srgb",
|
|
34
|
+
desc: "The output colourspace",
|
|
35
|
+
},
|
|
36
|
+
};
|
|
41
37
|
|
|
42
38
|
// Command builder.
|
|
43
39
|
const builder = (yargs) => {
|
|
44
40
|
return yargs
|
|
45
41
|
.strict()
|
|
46
|
-
.example(
|
|
47
|
-
.epilog(
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
.example("$0 toColourspace rgb16", "Output 16 bits per pixel RGB")
|
|
43
|
+
.epilog(
|
|
44
|
+
"For more information on available options, please visit https://sharp.pixelplumbing.com/api-colour#tocolourspace",
|
|
45
|
+
)
|
|
46
|
+
.positional("colourspace", positionals.colourspace);
|
|
47
|
+
};
|
|
50
48
|
|
|
51
49
|
// Command handler.
|
|
52
50
|
const handler = (args) => {
|
|
53
|
-
return queue.push([
|
|
54
|
-
|
|
51
|
+
return args["#queue"].push([
|
|
52
|
+
"toColourspace",
|
|
53
|
+
(sharp) => sharp.toColourspace(args.colourspace),
|
|
54
|
+
]);
|
|
55
|
+
};
|
|
55
56
|
|
|
56
57
|
// Exports.
|
|
57
|
-
|
|
58
|
-
command:
|
|
59
|
-
aliases:
|
|
60
|
-
describe:
|
|
58
|
+
export default {
|
|
59
|
+
command: "toColourspace <colourspace>",
|
|
60
|
+
aliases: "toColorspace",
|
|
61
|
+
describe: "Set the output colourspace",
|
|
61
62
|
builder,
|
|
62
|
-
handler
|
|
63
|
-
}
|
|
63
|
+
handler,
|
|
64
|
+
};
|
|
@@ -23,165 +23,196 @@
|
|
|
23
23
|
|
|
24
24
|
// @see http://sharp.pixelplumbing.com/api-composite#composite
|
|
25
25
|
|
|
26
|
-
// Strict mode.
|
|
27
|
-
'use strict'
|
|
28
|
-
|
|
29
26
|
// Local modules.
|
|
30
|
-
|
|
31
|
-
const queue = require('../../lib/queue')
|
|
27
|
+
import constants from "../../lib/constants.js";
|
|
32
28
|
|
|
33
29
|
// Helpers.
|
|
34
|
-
function getValueAt
|
|
30
|
+
function getValueAt(arrayLike, index) {
|
|
35
31
|
if (Array.isArray(arrayLike)) {
|
|
36
|
-
return arrayLike[Math.min(index, arrayLike.length - 1)]
|
|
32
|
+
return arrayLike[Math.min(index, arrayLike.length - 1)];
|
|
37
33
|
}
|
|
38
|
-
return arrayLike
|
|
34
|
+
return arrayLike;
|
|
39
35
|
}
|
|
40
36
|
|
|
41
|
-
function hasOwnProperty
|
|
42
|
-
return obj != null && Object.prototype.hasOwnProperty.call(obj, prop)
|
|
37
|
+
function hasOwnProperty(obj, prop) {
|
|
38
|
+
return obj != null && Object.prototype.hasOwnProperty.call(obj, prop);
|
|
43
39
|
}
|
|
44
40
|
|
|
45
41
|
// Configure.
|
|
46
42
|
const positionals = {
|
|
47
43
|
images: {
|
|
48
|
-
desc:
|
|
44
|
+
desc: "Path to an image file",
|
|
49
45
|
normalize: true,
|
|
50
|
-
type:
|
|
51
|
-
}
|
|
52
|
-
}
|
|
46
|
+
type: "string",
|
|
47
|
+
},
|
|
48
|
+
};
|
|
53
49
|
|
|
54
50
|
const options = {
|
|
55
51
|
blend: {
|
|
56
52
|
choices: constants.BLEND,
|
|
57
|
-
defaultDescription:
|
|
58
|
-
desc:
|
|
53
|
+
defaultDescription: "over",
|
|
54
|
+
desc: "How to blend this image with the image below",
|
|
59
55
|
},
|
|
60
56
|
create: {
|
|
61
|
-
desc:
|
|
57
|
+
desc: "Describes a blank overlay to be created",
|
|
62
58
|
hidden: true,
|
|
63
|
-
type:
|
|
59
|
+
type: "boolean",
|
|
64
60
|
},
|
|
65
|
-
|
|
66
|
-
desc:
|
|
67
|
-
type:
|
|
61
|
+
"create.background": {
|
|
62
|
+
desc: "Background of the blank overlay to be created, parsed by the color module",
|
|
63
|
+
type: "string",
|
|
68
64
|
},
|
|
69
|
-
|
|
65
|
+
"create.channels": {
|
|
70
66
|
choices: [3, 4],
|
|
71
67
|
default: 3,
|
|
72
|
-
desc:
|
|
68
|
+
desc: "Number of channels of the blank overlay to be created",
|
|
69
|
+
nargs: 1,
|
|
73
70
|
},
|
|
74
|
-
|
|
75
|
-
desc:
|
|
76
|
-
|
|
71
|
+
"create.height": {
|
|
72
|
+
desc: "Height of the blank overlay to be created",
|
|
73
|
+
nargs: 1,
|
|
74
|
+
type: "number",
|
|
77
75
|
},
|
|
78
|
-
|
|
79
|
-
desc:
|
|
80
|
-
|
|
76
|
+
"create.width": {
|
|
77
|
+
desc: "Width of the blank overlay to be created",
|
|
78
|
+
nargs: 1,
|
|
79
|
+
type: "number",
|
|
81
80
|
},
|
|
82
81
|
density: {
|
|
83
|
-
desc:
|
|
82
|
+
desc: "Number representing the DPI for vector images",
|
|
84
83
|
defaultDescription: 72,
|
|
85
|
-
|
|
84
|
+
nargs: 1,
|
|
85
|
+
type: "number",
|
|
86
86
|
},
|
|
87
87
|
gravity: {
|
|
88
88
|
choices: constants.GRAVITY,
|
|
89
|
-
defaultDescription:
|
|
90
|
-
desc:
|
|
89
|
+
defaultDescription: "centre",
|
|
90
|
+
desc: "Gravity at which to place the overlay",
|
|
91
91
|
},
|
|
92
92
|
left: {
|
|
93
|
-
desc:
|
|
94
|
-
implies:
|
|
95
|
-
|
|
93
|
+
desc: "The pixel offset from the left edge",
|
|
94
|
+
implies: "top",
|
|
95
|
+
nargs: 1,
|
|
96
|
+
type: "number",
|
|
96
97
|
},
|
|
97
98
|
premultiplied: {
|
|
98
|
-
desc:
|
|
99
|
-
type:
|
|
99
|
+
desc: "Avoid premultiplying the image",
|
|
100
|
+
type: "boolean",
|
|
100
101
|
},
|
|
101
102
|
tile: {
|
|
102
|
-
desc:
|
|
103
|
-
type:
|
|
103
|
+
desc: "Repeat the overlay image across the entire image with the given gravity",
|
|
104
|
+
type: "boolean",
|
|
104
105
|
},
|
|
105
106
|
top: {
|
|
106
|
-
desc:
|
|
107
|
-
implies:
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
107
|
+
desc: "The pixel offset from the top edge",
|
|
108
|
+
implies: "left",
|
|
109
|
+
nargs: 1,
|
|
110
|
+
type: "number",
|
|
111
|
+
},
|
|
112
|
+
};
|
|
111
113
|
|
|
112
114
|
// Command builder.
|
|
113
115
|
const builder = (yargs) => {
|
|
114
|
-
const optionNames = Object.keys(options)
|
|
116
|
+
const optionNames = Object.keys(options);
|
|
115
117
|
return yargs
|
|
116
118
|
.strict()
|
|
117
|
-
.example(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
119
|
+
.example(
|
|
120
|
+
"$0 composite ./input.png --gravity southeast",
|
|
121
|
+
"The output will be the input composited with ./input.png with SE gravity",
|
|
122
|
+
)
|
|
123
|
+
.example(
|
|
124
|
+
"$0 composite ./layer1.png --gravity northwest ./layer2.png --gravity southeast",
|
|
125
|
+
"The output will be the input composited with ./layer1.png with NW gravity and ./layer2.png with SE gravity",
|
|
126
|
+
)
|
|
127
|
+
.example(
|
|
128
|
+
"$0 composite ./overlay.png --tile --blend saturate",
|
|
129
|
+
"The output will be the input composited with ./overlay.png saturated over the entire image",
|
|
130
|
+
)
|
|
131
|
+
.epilog(
|
|
132
|
+
"For more information on available options, please visit http://sharp.pixelplumbing.com/api-composite#composite",
|
|
133
|
+
)
|
|
134
|
+
.positional("images", positionals.images)
|
|
135
|
+
.check((argv) => {
|
|
136
|
+
if (
|
|
137
|
+
(!argv.images || argv.images.length === 0) &&
|
|
138
|
+
!hasOwnProperty(argv.create, "width")
|
|
139
|
+
) {
|
|
140
|
+
throw new Error(
|
|
141
|
+
"Expected at least one of images positional or create option",
|
|
142
|
+
);
|
|
125
143
|
}
|
|
126
|
-
return true
|
|
144
|
+
return true;
|
|
127
145
|
})
|
|
128
146
|
.options(options)
|
|
129
|
-
.group(optionNames,
|
|
130
|
-
}
|
|
147
|
+
.group(optionNames, "Command Options");
|
|
148
|
+
};
|
|
131
149
|
|
|
132
150
|
// Command handler.
|
|
133
151
|
const handler = (args) => {
|
|
134
|
-
if (
|
|
135
|
-
|
|
136
|
-
|
|
152
|
+
if (
|
|
153
|
+
(hasOwnProperty(args.create, "width") &&
|
|
154
|
+
!hasOwnProperty(args.create, "height")) ||
|
|
155
|
+
(hasOwnProperty(args.create, "height") &&
|
|
156
|
+
!hasOwnProperty(args.create, "width"))
|
|
157
|
+
) {
|
|
158
|
+
throw new Error("Expected both of create.width and create.height options");
|
|
137
159
|
}
|
|
138
160
|
|
|
139
|
-
const inputs = []
|
|
140
|
-
if (hasOwnProperty(args.create,
|
|
141
|
-
const { channels, background, width, height } = args.create
|
|
142
|
-
const length = Math.max(width.length ?? 0, height.length ?? 0)
|
|
143
|
-
if (length > 0) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
161
|
+
const inputs = [];
|
|
162
|
+
if (hasOwnProperty(args.create, "width")) {
|
|
163
|
+
const { channels, background, width, height } = args.create;
|
|
164
|
+
const length = Math.max(width.length ?? 0, height.length ?? 0);
|
|
165
|
+
if (length > 0) {
|
|
166
|
+
// Width or height (or both) is an array.
|
|
167
|
+
inputs.push(
|
|
168
|
+
...Array.from({ length }, (_, idx) => idx).map((idx) => ({
|
|
169
|
+
create: {
|
|
170
|
+
width: getValueAt(width, idx),
|
|
171
|
+
height: getValueAt(height, idx),
|
|
172
|
+
channels: getValueAt(channels, idx),
|
|
173
|
+
background: getValueAt(background, idx),
|
|
174
|
+
},
|
|
175
|
+
})),
|
|
176
|
+
);
|
|
177
|
+
} else {
|
|
178
|
+
// Both width and height are numbers.
|
|
179
|
+
inputs.push({ create: args.create });
|
|
154
180
|
}
|
|
155
181
|
}
|
|
156
|
-
if (args.images) inputs.push(...args.images)
|
|
182
|
+
if (args.images) inputs.push(...args.images);
|
|
157
183
|
|
|
158
184
|
// @see http://sharp.pixelplumbing.com/api-composite#composite
|
|
159
|
-
return queue.push([
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
185
|
+
return args["#queue"].push([
|
|
186
|
+
"composite",
|
|
187
|
+
(sharp) => {
|
|
188
|
+
return sharp.composite(
|
|
189
|
+
inputs.map((input, idx) => ({
|
|
190
|
+
animated: args.animated,
|
|
191
|
+
autoOrient: args.autoOrient,
|
|
192
|
+
blend: getValueAt(args.blend, idx),
|
|
193
|
+
density: getValueAt(args.density, idx),
|
|
194
|
+
failOn: args.failOn,
|
|
195
|
+
gravity: getValueAt(args.gravity, idx),
|
|
196
|
+
ignoreIcc: getValueAt(args.ignoreIcc),
|
|
197
|
+
input,
|
|
198
|
+
left: getValueAt(args.left, idx),
|
|
199
|
+
limitInputChannels: args.limitInputChannels,
|
|
200
|
+
limitInputPixels: args.limitInputPixels,
|
|
201
|
+
pdfBackground: args.pdfBackground,
|
|
202
|
+
premultiplied: getValueAt(args.premultiplied, idx),
|
|
203
|
+
tile: getValueAt(args.tile, idx),
|
|
204
|
+
top: getValueAt(args.top, idx),
|
|
205
|
+
})),
|
|
206
|
+
);
|
|
207
|
+
},
|
|
208
|
+
]);
|
|
209
|
+
};
|
|
180
210
|
|
|
181
211
|
// Exports.
|
|
182
|
-
|
|
183
|
-
command:
|
|
184
|
-
describe:
|
|
212
|
+
export default {
|
|
213
|
+
command: "composite [images..]",
|
|
214
|
+
describe:
|
|
215
|
+
"Composite image(s) over the processed (resized, extracted etc.) image",
|
|
185
216
|
builder,
|
|
186
|
-
handler
|
|
187
|
-
}
|
|
217
|
+
handler,
|
|
218
|
+
};
|
package/cmd/operations/affine.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* The MIT License (MIT)
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2019 Mark van Seventer
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
7
7
|
* this software and associated documentation files (the "Software"), to deal in
|
|
@@ -23,88 +23,94 @@
|
|
|
23
23
|
|
|
24
24
|
// @see https://sharp.pixelplumbing.com/api-operation#affine
|
|
25
25
|
|
|
26
|
-
// Strict mode.
|
|
27
|
-
'use strict'
|
|
28
|
-
|
|
29
|
-
// Package modules.
|
|
30
|
-
const pick = require('lodash.pick')
|
|
31
|
-
|
|
32
26
|
// Local modules.
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
import constants from "../../lib/constants.js";
|
|
28
|
+
import { pick } from "../../lib/utils.js";
|
|
35
29
|
|
|
36
30
|
// Configure.
|
|
37
31
|
const placeholders = {
|
|
38
32
|
matrix: {
|
|
39
|
-
desc:
|
|
33
|
+
desc: "Affine transformation matrix",
|
|
40
34
|
nargs: 2 * 2,
|
|
41
|
-
type:
|
|
42
|
-
}
|
|
43
|
-
}
|
|
35
|
+
type: "number",
|
|
36
|
+
},
|
|
37
|
+
};
|
|
44
38
|
|
|
45
39
|
const options = {
|
|
46
40
|
background: {
|
|
47
|
-
defaultDescription:
|
|
48
|
-
desc:
|
|
49
|
-
type:
|
|
41
|
+
defaultDescription: "#000000",
|
|
42
|
+
desc: "String parsed by the color module to extract values for red, green, blue and alpha",
|
|
43
|
+
type: "string",
|
|
50
44
|
},
|
|
51
45
|
idx: {
|
|
52
|
-
defaultDescription:
|
|
53
|
-
desc:
|
|
54
|
-
|
|
46
|
+
defaultDescription: "0",
|
|
47
|
+
desc: "The input horizontal offset",
|
|
48
|
+
nargs: 1,
|
|
49
|
+
type: "number",
|
|
55
50
|
},
|
|
56
51
|
idy: {
|
|
57
|
-
defaultDescription:
|
|
58
|
-
desc:
|
|
59
|
-
|
|
52
|
+
defaultDescription: "0",
|
|
53
|
+
desc: "The input vertical offset",
|
|
54
|
+
nargs: 1,
|
|
55
|
+
type: "number",
|
|
60
56
|
},
|
|
61
57
|
odx: {
|
|
62
|
-
defaultDescription:
|
|
63
|
-
desc:
|
|
64
|
-
|
|
58
|
+
defaultDescription: "0",
|
|
59
|
+
desc: "The output horizontal offset",
|
|
60
|
+
nargs: 1,
|
|
61
|
+
type: "number",
|
|
65
62
|
},
|
|
66
63
|
ody: {
|
|
67
|
-
defaultDescription:
|
|
68
|
-
desc:
|
|
69
|
-
|
|
64
|
+
defaultDescription: "0",
|
|
65
|
+
desc: "The output vertical offset",
|
|
66
|
+
nargs: 1,
|
|
67
|
+
type: "number",
|
|
70
68
|
},
|
|
71
69
|
interpolate: {
|
|
72
70
|
choices: constants.INTERPOLATORS,
|
|
73
|
-
defaultDescription:
|
|
74
|
-
desc:
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
const optionNames = Object.keys(options)
|
|
71
|
+
defaultDescription: "bicubic",
|
|
72
|
+
desc: "The input horizontal offset",
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
const optionNames = Object.keys(options);
|
|
78
76
|
|
|
79
77
|
// Command builder.
|
|
80
78
|
const builder = (yargs) => {
|
|
81
79
|
return yargs
|
|
82
80
|
.strict()
|
|
83
|
-
.example(
|
|
84
|
-
.epilog(
|
|
85
|
-
|
|
81
|
+
.example("$0 affine 1 0.3 0.1 0.7 --background white --interpolate nohalo")
|
|
82
|
+
.epilog(
|
|
83
|
+
"For more information on available options, please visit https://sharp.pixelplumbing.com/api-operation#affine",
|
|
84
|
+
)
|
|
85
|
+
.check((argv) => {
|
|
86
86
|
if (!(Array.isArray(argv.matrix) && argv.matrix.length === 4)) {
|
|
87
|
-
throw new Error(
|
|
87
|
+
throw new Error("Expected matrix positional to have 4 values");
|
|
88
88
|
}
|
|
89
|
-
return true
|
|
89
|
+
return true;
|
|
90
90
|
})
|
|
91
|
-
.positional(
|
|
91
|
+
.positional("matrix", placeholders.matrix)
|
|
92
92
|
.options(options)
|
|
93
|
-
.group(optionNames,
|
|
94
|
-
}
|
|
93
|
+
.group(optionNames, "Command Options");
|
|
94
|
+
};
|
|
95
95
|
|
|
96
96
|
// Command handler.
|
|
97
97
|
const handler = (args) => {
|
|
98
|
-
return queue.push([
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
return args["#queue"].push([
|
|
99
|
+
"affine",
|
|
100
|
+
(sharp) => {
|
|
101
|
+
const { matrix } = args;
|
|
102
|
+
return sharp.affine(
|
|
103
|
+
[matrix.slice(0, 2), matrix.slice(2, 4)],
|
|
104
|
+
pick(args, optionNames),
|
|
105
|
+
);
|
|
106
|
+
},
|
|
107
|
+
]);
|
|
108
|
+
};
|
|
103
109
|
|
|
104
110
|
// Exports.
|
|
105
|
-
|
|
106
|
-
command:
|
|
107
|
-
describe:
|
|
111
|
+
export default {
|
|
112
|
+
command: "affine <matrix..>",
|
|
113
|
+
describe: "Perform an affine transform on an image",
|
|
108
114
|
builder,
|
|
109
|
-
handler
|
|
110
|
-
}
|
|
115
|
+
handler,
|
|
116
|
+
};
|
package/cmd/operations/blur.js
CHANGED
|
@@ -23,65 +23,68 @@
|
|
|
23
23
|
|
|
24
24
|
// @see https://sharp.pixelplumbing.com/api-operation#blur
|
|
25
25
|
|
|
26
|
-
// Strict mode.
|
|
27
|
-
'use strict'
|
|
28
|
-
|
|
29
|
-
// Local modules.
|
|
30
|
-
const queue = require('../../lib/queue')
|
|
31
|
-
|
|
32
26
|
// Configure.
|
|
33
27
|
const positionals = {
|
|
34
28
|
sigma: {
|
|
35
|
-
desc:
|
|
36
|
-
defaultDescription:
|
|
37
|
-
type:
|
|
38
|
-
}
|
|
39
|
-
}
|
|
29
|
+
desc: "The sigma of the Gaussian mask",
|
|
30
|
+
defaultDescription: "1 + radius / 2",
|
|
31
|
+
type: "number",
|
|
32
|
+
},
|
|
33
|
+
};
|
|
40
34
|
|
|
41
35
|
const options = {
|
|
42
36
|
minAmplitude: {
|
|
43
37
|
defaultDescription: 0.2,
|
|
44
|
-
desc:
|
|
45
|
-
|
|
38
|
+
desc: "A smaller value will generate a larger, more accurate mask",
|
|
39
|
+
nargs: 1,
|
|
40
|
+
type: "number",
|
|
46
41
|
},
|
|
47
42
|
precision: {
|
|
48
|
-
choices: [
|
|
49
|
-
defaultDescription:
|
|
50
|
-
desc:
|
|
51
|
-
}
|
|
52
|
-
}
|
|
43
|
+
choices: ["approximate", "float", "integer"],
|
|
44
|
+
defaultDescription: "integer",
|
|
45
|
+
desc: "How accurate the operation should be",
|
|
46
|
+
},
|
|
47
|
+
};
|
|
53
48
|
|
|
54
49
|
// Command builder.
|
|
55
50
|
const builder = (yargs) => {
|
|
56
|
-
const optionNames = Object.keys(options)
|
|
51
|
+
const optionNames = Object.keys(options);
|
|
57
52
|
return yargs
|
|
58
53
|
.strict()
|
|
59
|
-
.example(
|
|
60
|
-
.example(
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
.example("$0 blur", "The output will be a fast 3x3 box blurred image")
|
|
55
|
+
.example(
|
|
56
|
+
"$0 blur 5",
|
|
57
|
+
"The output will be a slower but more accurate Gaussian blurred image",
|
|
58
|
+
)
|
|
59
|
+
.epilog(
|
|
60
|
+
"For more information on available options, please visit https://sharp.pixelplumbing.com/api-operation#blur",
|
|
61
|
+
)
|
|
62
|
+
.positional("sigma", positionals.sigma)
|
|
63
63
|
.options(options)
|
|
64
|
-
.group(optionNames,
|
|
65
|
-
}
|
|
64
|
+
.group(optionNames, "Command Options");
|
|
65
|
+
};
|
|
66
66
|
|
|
67
67
|
// Command handler.
|
|
68
68
|
const handler = (args) => {
|
|
69
|
-
return queue.push([
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
69
|
+
return args["#queue"].push([
|
|
70
|
+
"blur",
|
|
71
|
+
(sharp) => {
|
|
72
|
+
if (args.minAmplitude || args.precision) {
|
|
73
|
+
return sharp.blur({
|
|
74
|
+
minAmplitude: args.minAmplitude,
|
|
75
|
+
precision: args.precision,
|
|
76
|
+
sigma: args.sigma,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return sharp.blur(args.sigma);
|
|
80
|
+
},
|
|
81
|
+
]);
|
|
82
|
+
};
|
|
80
83
|
|
|
81
84
|
// Exports.
|
|
82
|
-
|
|
83
|
-
command:
|
|
84
|
-
describe:
|
|
85
|
+
export default {
|
|
86
|
+
command: "blur [sigma]",
|
|
87
|
+
describe: "Blur the image",
|
|
85
88
|
builder,
|
|
86
|
-
handler
|
|
87
|
-
}
|
|
89
|
+
handler,
|
|
90
|
+
};
|