@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
package/cmd/resizing/resize.js
CHANGED
|
@@ -23,102 +23,125 @@
|
|
|
23
23
|
|
|
24
24
|
// @see https://sharp.pixelplumbing.com/api-resize/
|
|
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 positionals = {
|
|
38
32
|
width: {
|
|
39
33
|
default: null,
|
|
40
|
-
desc:
|
|
41
|
-
type:
|
|
34
|
+
desc: "Pixels wide the resultant image should be",
|
|
35
|
+
type: "number",
|
|
42
36
|
},
|
|
43
37
|
height: {
|
|
44
38
|
default: null,
|
|
45
|
-
desc:
|
|
46
|
-
type:
|
|
47
|
-
}
|
|
48
|
-
}
|
|
39
|
+
desc: "Pixels high the resultant image should be",
|
|
40
|
+
type: "number",
|
|
41
|
+
},
|
|
42
|
+
};
|
|
49
43
|
|
|
50
44
|
const options = {
|
|
51
45
|
background: {
|
|
52
|
-
defaultDescription:
|
|
53
|
-
desc:
|
|
54
|
-
type:
|
|
46
|
+
defaultDescription: "rgba(0, 0, 0, 1)",
|
|
47
|
+
desc: "Background colour when fit is contain, parsed by the color module.",
|
|
48
|
+
type: "string",
|
|
55
49
|
},
|
|
56
50
|
fastShrinkOnLoad: {
|
|
57
51
|
defaultDescription: true,
|
|
58
|
-
desc:
|
|
59
|
-
type:
|
|
52
|
+
desc: "Take greater advantage of the JPEG and WebP shrink-on-load feature",
|
|
53
|
+
type: "boolean",
|
|
60
54
|
},
|
|
61
55
|
fit: {
|
|
62
56
|
choices: constants.FIT,
|
|
63
|
-
defaultDescription:
|
|
64
|
-
desc:
|
|
57
|
+
defaultDescription: "cover",
|
|
58
|
+
desc: "How the image should be resized to fit both provided dimensions",
|
|
65
59
|
},
|
|
66
60
|
kernel: {
|
|
67
61
|
choices: constants.KERNEL,
|
|
68
|
-
defaultDescription:
|
|
69
|
-
desc:
|
|
62
|
+
defaultDescription: "lanczos3",
|
|
63
|
+
desc: "The kernel to use for image reduction and the inferred interpolator to use for upsampling",
|
|
70
64
|
},
|
|
71
65
|
position: {
|
|
72
|
-
choices: [
|
|
73
|
-
|
|
74
|
-
|
|
66
|
+
choices: [
|
|
67
|
+
...constants.GRAVITY,
|
|
68
|
+
...constants.POSITION,
|
|
69
|
+
...constants.STRATEGY,
|
|
70
|
+
],
|
|
71
|
+
defaultDescription: "centre",
|
|
72
|
+
desc: "Position, gravity, or strategy to use when fit is cover or contain",
|
|
75
73
|
},
|
|
76
74
|
withoutEnlargement: {
|
|
77
|
-
desc:
|
|
78
|
-
type:
|
|
75
|
+
desc: "Do not enlarge if the width or height are already less than the specified dimensions",
|
|
76
|
+
type: "boolean",
|
|
79
77
|
},
|
|
80
78
|
withoutReduction: {
|
|
81
|
-
desc:
|
|
82
|
-
type:
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
const optionNames = Object.keys(options)
|
|
79
|
+
desc: "Do not reduce if the width or height are already greater than the specified dimensions",
|
|
80
|
+
type: "boolean",
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
const optionNames = Object.keys(options);
|
|
86
84
|
|
|
87
85
|
// Command builder.
|
|
88
86
|
const builder = (yargs) => {
|
|
89
87
|
return yargs
|
|
90
88
|
.strict()
|
|
91
|
-
.example(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
.example(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
.
|
|
100
|
-
|
|
89
|
+
.example(
|
|
90
|
+
"$0 resize 100",
|
|
91
|
+
"The output will be 100 pixels wide, auto-scaled height",
|
|
92
|
+
)
|
|
93
|
+
.example(
|
|
94
|
+
"$0 resize --height 100",
|
|
95
|
+
"The output will be 100 pixels high, auto-scaled width",
|
|
96
|
+
)
|
|
97
|
+
.example(
|
|
98
|
+
'$0 resize 200 300 --background rgba(255,255,255,0.5) --fit contain --kernel nearest --position "right top"',
|
|
99
|
+
"The output will be 200 pixels wide and 300 pixels high containing a nearest-neighbour scaled version contained within the north-east corner of a semi-transparent white canvas",
|
|
100
|
+
)
|
|
101
|
+
.example(
|
|
102
|
+
"$0 resize 200 200 --fit cover --position entropy",
|
|
103
|
+
"The output will be a 200px square auto-cropped image",
|
|
104
|
+
)
|
|
105
|
+
.example(
|
|
106
|
+
"$0 resize 200 200 --withoutEnlargement",
|
|
107
|
+
"The output will be no wider and no higher than 200 pixels, and no larger than the input image",
|
|
108
|
+
)
|
|
109
|
+
.example(
|
|
110
|
+
"$0 resize 200 200 --withoutReduction",
|
|
111
|
+
"The output will be at least 200 pixels wide and 200 pixels high while maintaining aspect ratio, and no smaller than the input image",
|
|
112
|
+
)
|
|
113
|
+
.epilog(
|
|
114
|
+
"For more information on available options, please visit https://sharp.pixelplumbing.com/api-resize/",
|
|
115
|
+
)
|
|
116
|
+
.positional("width", positionals.width)
|
|
117
|
+
.positional("height", positionals.height)
|
|
118
|
+
.check((argv) => {
|
|
101
119
|
if (argv.width === null && argv.height === null) {
|
|
102
|
-
throw new Error(
|
|
120
|
+
throw new Error(
|
|
121
|
+
"Expected at least one of width and height positionals",
|
|
122
|
+
);
|
|
103
123
|
}
|
|
104
|
-
return true
|
|
124
|
+
return true;
|
|
105
125
|
})
|
|
106
126
|
.options(options)
|
|
107
|
-
.group(optionNames,
|
|
108
|
-
}
|
|
127
|
+
.group(optionNames, "Command Options");
|
|
128
|
+
};
|
|
109
129
|
|
|
110
130
|
// Command handler.
|
|
111
131
|
const handler = (args) => {
|
|
112
132
|
// @see https://sharp.pixelplumbing.com/api-resize#resize
|
|
113
|
-
return queue.push([
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
133
|
+
return args["#queue"].push([
|
|
134
|
+
"resize",
|
|
135
|
+
(sharp) => {
|
|
136
|
+
return sharp.resize(args.width, args.height, pick(args, optionNames));
|
|
137
|
+
},
|
|
138
|
+
]);
|
|
139
|
+
};
|
|
117
140
|
|
|
118
141
|
// Exports.
|
|
119
|
-
|
|
120
|
-
command:
|
|
121
|
-
describe:
|
|
142
|
+
export default {
|
|
143
|
+
command: "resize [width] [height]",
|
|
144
|
+
describe: "Resize image to width, height, or width × height",
|
|
122
145
|
builder,
|
|
123
|
-
handler
|
|
124
|
-
}
|
|
146
|
+
handler,
|
|
147
|
+
};
|
package/cmd/resizing/trim.js
CHANGED
|
@@ -21,62 +21,85 @@
|
|
|
21
21
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
// @see https://sharp.
|
|
25
|
-
|
|
26
|
-
// Strict mode.
|
|
27
|
-
'use strict'
|
|
28
|
-
|
|
29
|
-
// Local modules.
|
|
30
|
-
const queue = require('../../lib/queue')
|
|
24
|
+
// @see https://sharp.pixelplumbing.com/api-resize#trim
|
|
31
25
|
|
|
32
26
|
// Configure.
|
|
33
27
|
const positionals = {
|
|
34
28
|
threshold: {
|
|
35
|
-
desc:
|
|
29
|
+
desc: "The allowed difference from the top-left pixel",
|
|
36
30
|
defaultDescription: 10,
|
|
37
|
-
type:
|
|
38
|
-
}
|
|
39
|
-
}
|
|
31
|
+
type: "number",
|
|
32
|
+
},
|
|
33
|
+
};
|
|
40
34
|
|
|
41
35
|
const options = {
|
|
42
36
|
background: {
|
|
43
|
-
defaultDescription:
|
|
44
|
-
desc:
|
|
45
|
-
type:
|
|
37
|
+
defaultDescription: "top-left pixel",
|
|
38
|
+
desc: "Background colour, parsed by the color module",
|
|
39
|
+
type: "string",
|
|
46
40
|
},
|
|
47
41
|
lineArt: {
|
|
48
42
|
default: false,
|
|
49
|
-
desc:
|
|
50
|
-
type:
|
|
51
|
-
}
|
|
52
|
-
|
|
43
|
+
desc: "Does the input more closely resemble line art rather than being photographic",
|
|
44
|
+
type: "boolean",
|
|
45
|
+
},
|
|
46
|
+
margin: {
|
|
47
|
+
desc: "Leave a margin around trimmed content",
|
|
48
|
+
nargs: 1,
|
|
49
|
+
type: "number",
|
|
50
|
+
},
|
|
51
|
+
};
|
|
53
52
|
|
|
54
53
|
// Command builder.
|
|
55
54
|
const builder = (yargs) => {
|
|
56
|
-
const optionNames = Object.keys(options)
|
|
55
|
+
const optionNames = Object.keys(options);
|
|
57
56
|
return yargs
|
|
58
57
|
.strict()
|
|
59
|
-
.example(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
.
|
|
64
|
-
|
|
58
|
+
.example(
|
|
59
|
+
"$0 trim",
|
|
60
|
+
"Trim pixels with a colour similar to that of the top-left pixel",
|
|
61
|
+
)
|
|
62
|
+
.example(
|
|
63
|
+
"$0 trim 0",
|
|
64
|
+
"Trim pixels with the exact same colour as that of the top-left pixel",
|
|
65
|
+
)
|
|
66
|
+
.example(
|
|
67
|
+
'$0 trim --background "#FF0000"',
|
|
68
|
+
"Trim pixels with a similar colour to red",
|
|
69
|
+
)
|
|
70
|
+
.example("$0 trim 42 --background yellow", 'Trim all "yellow-ish" pixels')
|
|
71
|
+
.example(
|
|
72
|
+
"$0 trim --margin 10",
|
|
73
|
+
"Trim image leaving (up to) 10 pixel margin around the trimmed content",
|
|
74
|
+
)
|
|
75
|
+
.epilog(
|
|
76
|
+
"For more information on available options, please visit https://sharp.pixelplumbing.com/api-resize#trim",
|
|
77
|
+
)
|
|
78
|
+
.positional("threshold", positionals.threshold)
|
|
65
79
|
.options(options)
|
|
66
|
-
.group(optionNames,
|
|
67
|
-
}
|
|
80
|
+
.group(optionNames, "Command Options");
|
|
81
|
+
};
|
|
68
82
|
|
|
69
83
|
// Command handler.
|
|
70
84
|
const handler = (args) => {
|
|
71
|
-
return queue.push([
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
85
|
+
return args["#queue"].push([
|
|
86
|
+
"trim",
|
|
87
|
+
(sharp) => {
|
|
88
|
+
return sharp.trim({
|
|
89
|
+
background: args.background,
|
|
90
|
+
lineArt: args.lineArt,
|
|
91
|
+
margin: args.margin,
|
|
92
|
+
threshold: args.threshold,
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
]);
|
|
96
|
+
};
|
|
75
97
|
|
|
76
98
|
// Exports.
|
|
77
|
-
|
|
78
|
-
command:
|
|
79
|
-
describe:
|
|
99
|
+
export default {
|
|
100
|
+
command: "trim [threshold]",
|
|
101
|
+
describe:
|
|
102
|
+
"Trim pixels from all edges that contain values similar to the given background color, which defaults to that of the top-left pixel",
|
|
80
103
|
builder,
|
|
81
|
-
handler
|
|
82
|
-
}
|
|
104
|
+
handler,
|
|
105
|
+
};
|
|
@@ -21,24 +21,28 @@
|
|
|
21
21
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
//
|
|
25
|
-
|
|
24
|
+
// Package modules.
|
|
25
|
+
import js from "@eslint/js";
|
|
26
|
+
import globals from "globals";
|
|
27
|
+
import { defineConfig, globalIgnores } from "eslint/config";
|
|
26
28
|
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
+
// Exports.
|
|
30
|
+
export default defineConfig([
|
|
31
|
+
globalIgnores(["coverage/**", ".nyc_output/**"]),
|
|
32
|
+
js.configs.recommended,
|
|
29
33
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
drain: {
|
|
34
|
-
value: (initialValue) => queue.reduce((acc, [, cb]) => cb(acc), initialValue)
|
|
34
|
+
{
|
|
35
|
+
files: ["**/*.{js,mjs,cjs}"],
|
|
36
|
+
languageOptions: { globals: globals.node },
|
|
35
37
|
},
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
{
|
|
40
|
+
files: ["test/**/*.js"],
|
|
41
|
+
languageOptions: {
|
|
42
|
+
globals: {
|
|
43
|
+
...globals.node,
|
|
44
|
+
...globals.mocha,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
]);
|