@depup/sharp-cli 5.3.0-depup.0 → 6.1.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/CHANGELOG.md +26 -0
- package/README.md +6 -9
- package/bin/cli.js +5 -5
- package/changes.json +4 -16
- package/cmd/channel-manipulation/bandbool.js +6 -7
- package/cmd/channel-manipulation/ensure-alpha.js +5 -8
- package/cmd/channel-manipulation/extract-channel.js +3 -7
- package/cmd/channel-manipulation/join-channel.js +5 -8
- package/cmd/channel-manipulation/remove-alpha.js +2 -8
- package/cmd/colour-manipulation/greyscale.js +2 -8
- package/cmd/colour-manipulation/pipeline-colourspace.js +4 -8
- package/cmd/colour-manipulation/tint.js +3 -8
- package/cmd/colour-manipulation/tocolourspace.js +3 -7
- package/cmd/compositing/composite.js +10 -7
- package/cmd/operations/affine.js +9 -11
- package/cmd/operations/blur.js +3 -8
- package/cmd/operations/boolean.js +3 -7
- package/cmd/operations/clahe.js +4 -9
- package/cmd/operations/convolve.js +5 -9
- package/cmd/operations/dilate.js +2 -8
- package/cmd/operations/erode.js +2 -8
- package/cmd/operations/flatten.js +2 -8
- package/cmd/operations/flip.js +3 -8
- package/cmd/operations/flop.js +3 -8
- package/cmd/operations/gamma.js +2 -8
- package/cmd/operations/linear.js +2 -8
- package/cmd/operations/median.js +2 -8
- package/cmd/operations/modulate.js +10 -9
- package/cmd/operations/negate.js +2 -8
- package/cmd/operations/normalise.js +5 -9
- package/cmd/operations/recomb.js +2 -8
- package/cmd/operations/rotate.js +2 -8
- package/cmd/operations/sharpen.js +8 -9
- package/cmd/operations/threshold.js +2 -8
- package/cmd/operations/unflatten.js +2 -8
- package/cmd/output.js +7 -10
- package/cmd/resizing/extend.js +4 -10
- package/cmd/resizing/extract.js +3 -9
- package/cmd/resizing/resize.js +30 -16
- package/cmd/resizing/trim.js +12 -8
- package/{lib/queue.js → eslint.config.mjs} +20 -17
- package/lib/cli.js +473 -333
- package/lib/constants.js +4 -6
- package/lib/convert.js +120 -56
- package/lib/index.js +46 -17
- package/lib/utils.js +50 -0
- package/package.json +32 -34
package/cmd/resizing/extract.js
CHANGED
|
@@ -23,14 +23,8 @@
|
|
|
23
23
|
|
|
24
24
|
// @see https://sharp.pixelplumbing.com/api-resize#extract
|
|
25
25
|
|
|
26
|
-
// Strict mode.
|
|
27
|
-
"use strict";
|
|
28
|
-
|
|
29
|
-
// Package modules.
|
|
30
|
-
const pick = require("lodash.pick");
|
|
31
|
-
|
|
32
26
|
// Local modules.
|
|
33
|
-
|
|
27
|
+
import { pick } from "../../lib/utils.js";
|
|
34
28
|
|
|
35
29
|
// Configure.
|
|
36
30
|
const positionals = {
|
|
@@ -67,7 +61,7 @@ const builder = (yargs) => {
|
|
|
67
61
|
|
|
68
62
|
// Command handler.
|
|
69
63
|
const handler = (args) => {
|
|
70
|
-
return queue.push([
|
|
64
|
+
return args["#queue"].push([
|
|
71
65
|
"extract",
|
|
72
66
|
(sharp) => {
|
|
73
67
|
return sharp.extract(pick(args, Object.keys(positionals)));
|
|
@@ -76,7 +70,7 @@ const handler = (args) => {
|
|
|
76
70
|
};
|
|
77
71
|
|
|
78
72
|
// Exports.
|
|
79
|
-
|
|
73
|
+
export default {
|
|
80
74
|
command: "extract <top> <left> <width> <height>",
|
|
81
75
|
describe: "Extract a region of the image",
|
|
82
76
|
builder,
|
package/cmd/resizing/resize.js
CHANGED
|
@@ -23,27 +23,35 @@
|
|
|
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";
|
|
29
|
+
|
|
30
|
+
// Helpers.
|
|
31
|
+
const resolveDimension = (dimension, metadataDimension) => {
|
|
32
|
+
if (dimension == null) return null;
|
|
33
|
+
if (typeof dimension === "string" && dimension.endsWith("%")) {
|
|
34
|
+
if (metadataDimension == null) {
|
|
35
|
+
throw new Error("Input metadata is required to resolve percentage");
|
|
36
|
+
}
|
|
37
|
+
return Math.round(
|
|
38
|
+
(metadataDimension * Number(dimension.slice(0, -1))) / 100,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return Number(dimension);
|
|
42
|
+
};
|
|
35
43
|
|
|
36
44
|
// Configure.
|
|
37
45
|
const positionals = {
|
|
38
46
|
width: {
|
|
39
47
|
default: null,
|
|
40
|
-
desc: "Pixels wide the resultant image should be",
|
|
41
|
-
type: "
|
|
48
|
+
desc: "Pixels or percentage wide the resultant image should be",
|
|
49
|
+
type: "string",
|
|
42
50
|
},
|
|
43
51
|
height: {
|
|
44
52
|
default: null,
|
|
45
|
-
desc: "Pixels high the resultant image should be",
|
|
46
|
-
type: "
|
|
53
|
+
desc: "Pixels or percentage high the resultant image should be",
|
|
54
|
+
type: "string",
|
|
47
55
|
},
|
|
48
56
|
};
|
|
49
57
|
|
|
@@ -100,6 +108,10 @@ const builder = (yargs) => {
|
|
|
100
108
|
"$0 resize --height 100",
|
|
101
109
|
"The output will be 100 pixels high, auto-scaled width",
|
|
102
110
|
)
|
|
111
|
+
.example(
|
|
112
|
+
"$0 resize 50%",
|
|
113
|
+
"The output will be 50% of the input width, auto-scaled height",
|
|
114
|
+
)
|
|
103
115
|
.example(
|
|
104
116
|
'$0 resize 200 300 --background rgba(255,255,255,0.5) --fit contain --kernel nearest --position "right top"',
|
|
105
117
|
"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",
|
|
@@ -136,16 +148,18 @@ const builder = (yargs) => {
|
|
|
136
148
|
// Command handler.
|
|
137
149
|
const handler = (args) => {
|
|
138
150
|
// @see https://sharp.pixelplumbing.com/api-resize#resize
|
|
139
|
-
return queue.push([
|
|
151
|
+
return args["#queue"].push([
|
|
140
152
|
"resize",
|
|
141
|
-
(sharp) => {
|
|
142
|
-
|
|
153
|
+
(sharp, { metadata } = {}) => {
|
|
154
|
+
const width = resolveDimension(args.width, metadata?.width);
|
|
155
|
+
const height = resolveDimension(args.height, metadata?.height);
|
|
156
|
+
return sharp.resize(width, height, pick(args, optionNames));
|
|
143
157
|
},
|
|
144
158
|
]);
|
|
145
159
|
};
|
|
146
160
|
|
|
147
161
|
// Exports.
|
|
148
|
-
|
|
162
|
+
export default {
|
|
149
163
|
command: "resize [width] [height]",
|
|
150
164
|
describe: "Resize image to width, height, or width × height",
|
|
151
165
|
builder,
|
package/cmd/resizing/trim.js
CHANGED
|
@@ -23,12 +23,6 @@
|
|
|
23
23
|
|
|
24
24
|
// @see https://sharp.pixelplumbing.com/api-resize#trim
|
|
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
|
threshold: {
|
|
@@ -49,6 +43,11 @@ const options = {
|
|
|
49
43
|
desc: "Does the input more closely resemble line art rather than being photographic",
|
|
50
44
|
type: "boolean",
|
|
51
45
|
},
|
|
46
|
+
margin: {
|
|
47
|
+
desc: "Leave a margin around trimmed content",
|
|
48
|
+
nargs: 1,
|
|
49
|
+
type: "number",
|
|
50
|
+
},
|
|
52
51
|
};
|
|
53
52
|
|
|
54
53
|
// Command builder.
|
|
@@ -69,6 +68,10 @@ const builder = (yargs) => {
|
|
|
69
68
|
"Trim pixels with a similar colour to red",
|
|
70
69
|
)
|
|
71
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
|
+
)
|
|
72
75
|
.epilog(
|
|
73
76
|
"For more information on available options, please visit https://sharp.pixelplumbing.com/api-resize#trim",
|
|
74
77
|
)
|
|
@@ -79,12 +82,13 @@ const builder = (yargs) => {
|
|
|
79
82
|
|
|
80
83
|
// Command handler.
|
|
81
84
|
const handler = (args) => {
|
|
82
|
-
return queue.push([
|
|
85
|
+
return args["#queue"].push([
|
|
83
86
|
"trim",
|
|
84
87
|
(sharp) => {
|
|
85
88
|
return sharp.trim({
|
|
86
89
|
background: args.background,
|
|
87
90
|
lineArt: args.lineArt,
|
|
91
|
+
margin: args.margin,
|
|
88
92
|
threshold: args.threshold,
|
|
89
93
|
});
|
|
90
94
|
},
|
|
@@ -92,7 +96,7 @@ const handler = (args) => {
|
|
|
92
96
|
};
|
|
93
97
|
|
|
94
98
|
// Exports.
|
|
95
|
-
|
|
99
|
+
export default {
|
|
96
100
|
command: "trim [threshold]",
|
|
97
101
|
describe:
|
|
98
102
|
"Trim pixels from all edges that contain values similar to the given background color, which defaults to that of the top-left pixel",
|
|
@@ -21,25 +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) =>
|
|
35
|
-
queue.reduce((acc, [, cb]) => cb(acc), initialValue),
|
|
34
|
+
{
|
|
35
|
+
files: ["**/*.{js,mjs,cjs}"],
|
|
36
|
+
languageOptions: { globals: globals.node },
|
|
36
37
|
},
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
{
|
|
40
|
+
files: ["test/**/*.js"],
|
|
41
|
+
languageOptions: {
|
|
42
|
+
globals: {
|
|
43
|
+
...globals.node,
|
|
44
|
+
...globals.mocha,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
41
47
|
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// Exports.
|
|
45
|
-
module.exports = queue;
|
|
48
|
+
]);
|