@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/constants.js
CHANGED
|
@@ -22,34 +22,42 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
// Strict mode.
|
|
25
|
-
|
|
25
|
+
"use strict";
|
|
26
26
|
|
|
27
27
|
// Package modules.
|
|
28
|
-
const sharp = require(
|
|
28
|
+
const sharp = require("sharp");
|
|
29
29
|
|
|
30
30
|
// Exports.
|
|
31
31
|
module.exports = {
|
|
32
32
|
BLEND: Object.keys(sharp.blend),
|
|
33
33
|
BOOL: Object.keys(sharp.bool),
|
|
34
|
-
CHANNEL: [
|
|
34
|
+
CHANNEL: ["red", "green", "blue", "alpha"],
|
|
35
35
|
COLOURSPACE: Object.keys(sharp.colourspace),
|
|
36
|
-
CONTAINER: [
|
|
37
|
-
DEPTH: [
|
|
38
|
-
EXTEND_WITH: [
|
|
39
|
-
FAIL_ON: [
|
|
36
|
+
CONTAINER: ["fs", "zip"],
|
|
37
|
+
DEPTH: ["onepixel", "onetile", "one"],
|
|
38
|
+
EXTEND_WITH: ["background", "copy", "repeat", "mirror"],
|
|
39
|
+
FAIL_ON: ["none", "truncated", "error", "warning"],
|
|
40
40
|
FIT: Object.keys(sharp.fit),
|
|
41
|
-
FORMAT: [
|
|
41
|
+
FORMAT: ["avif", "gif", "heif", "jpeg", "jpg", "png", "tiff", "webp"],
|
|
42
42
|
GRAVITY: Object.keys(sharp.gravity),
|
|
43
|
-
HEIF_COMPRESSION: [
|
|
43
|
+
HEIF_COMPRESSION: ["hevc", "av1"],
|
|
44
44
|
INTERPOLATORS: Object.keys(sharp.interpolators),
|
|
45
45
|
KERNEL: Object.keys(sharp.kernel),
|
|
46
|
-
LAYOUT: [
|
|
46
|
+
LAYOUT: ["dz", "google", "iiif", "iiif3", "zoomify"],
|
|
47
47
|
POSITION: Object.keys(sharp.position),
|
|
48
|
-
PRESETS: [
|
|
49
|
-
RESOLUTION_UNIT: [
|
|
48
|
+
PRESETS: ["default", "photo", "picture", "drawing", "icon", "text"],
|
|
49
|
+
RESOLUTION_UNIT: ["cm", "inch"],
|
|
50
50
|
STRATEGY: Object.keys(sharp.strategy),
|
|
51
51
|
TIFF_COMPRESSION: [
|
|
52
|
-
|
|
52
|
+
"ccittfax4",
|
|
53
|
+
"deflate",
|
|
54
|
+
"jpeg",
|
|
55
|
+
"jp2k",
|
|
56
|
+
"lzw",
|
|
57
|
+
"none",
|
|
58
|
+
"packbits",
|
|
59
|
+
"webp",
|
|
60
|
+
"zstd",
|
|
53
61
|
],
|
|
54
|
-
TIFF_PREDICTOR: [
|
|
55
|
-
}
|
|
62
|
+
TIFF_PREDICTOR: ["float", "horizontal", "none"],
|
|
63
|
+
};
|
package/lib/convert.js
CHANGED
|
@@ -22,32 +22,32 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
// Strict mode.
|
|
25
|
-
|
|
25
|
+
"use strict";
|
|
26
26
|
|
|
27
27
|
// Standard lib.
|
|
28
|
-
const fs = require(
|
|
29
|
-
const path = require(
|
|
28
|
+
const fs = require("fs");
|
|
29
|
+
const path = require("path");
|
|
30
|
+
const { pipeline } = require("stream/promises");
|
|
30
31
|
|
|
31
32
|
// Package modules.
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const sharp = require('sharp')
|
|
33
|
+
const { globSync } = require("glob");
|
|
34
|
+
const isDirectory = require("is-directory");
|
|
35
|
+
const sharp = require("sharp");
|
|
36
36
|
|
|
37
37
|
// Local modules.
|
|
38
|
-
const queue = require(
|
|
38
|
+
const queue = require("./queue");
|
|
39
39
|
|
|
40
40
|
// Configure.
|
|
41
41
|
const EXTENSIONS = {
|
|
42
|
-
avif:
|
|
43
|
-
dz:
|
|
44
|
-
gif:
|
|
45
|
-
heif:
|
|
46
|
-
jpeg:
|
|
47
|
-
png:
|
|
48
|
-
tiff:
|
|
49
|
-
webp:
|
|
50
|
-
}
|
|
42
|
+
avif: ".avif",
|
|
43
|
+
dz: "", // Determined by tile.container.
|
|
44
|
+
gif: ".gif",
|
|
45
|
+
heif: ".avif",
|
|
46
|
+
jpeg: ".jpg",
|
|
47
|
+
png: ".png",
|
|
48
|
+
tiff: ".tiff",
|
|
49
|
+
webp: ".webp",
|
|
50
|
+
};
|
|
51
51
|
|
|
52
52
|
// Exports.
|
|
53
53
|
module.exports = {
|
|
@@ -55,67 +55,62 @@ module.exports = {
|
|
|
55
55
|
files: (input, output, options) => {
|
|
56
56
|
// Resolve files.
|
|
57
57
|
const files = input.reduce((list, input) => {
|
|
58
|
-
return list.concat(globSync(input, { absolute: true }))
|
|
59
|
-
}, [])
|
|
58
|
+
return list.concat(globSync(input, { absolute: true }));
|
|
59
|
+
}, []);
|
|
60
60
|
|
|
61
61
|
if (files.length === 0) {
|
|
62
|
-
return Promise.reject(new Error(
|
|
62
|
+
return Promise.reject(new Error("No input files"));
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
// Process files.
|
|
66
|
-
const isBatch = files.length > 1
|
|
66
|
+
const isBatch = files.length > 1;
|
|
67
67
|
const promises = files.map((src) => {
|
|
68
68
|
// Create pipeline.
|
|
69
|
-
const transformer = queue.drain(sharp(options))
|
|
69
|
+
const transformer = queue.drain(sharp(options));
|
|
70
70
|
|
|
71
71
|
// Process output as a template.
|
|
72
|
-
const parts = path.parse(src)
|
|
73
|
-
const regex = /\{(root|dir|base|ext|name)\}/g
|
|
74
|
-
let dest = output
|
|
75
|
-
let match
|
|
72
|
+
const parts = path.parse(src);
|
|
73
|
+
const regex = /\{(root|dir|base|ext|name)\}/g;
|
|
74
|
+
let dest = output;
|
|
75
|
+
let match;
|
|
76
76
|
while ((match = regex.exec(output)) !== null) {
|
|
77
|
-
const [search, prop] = match
|
|
78
|
-
dest = dest.replace(search, parts[prop])
|
|
77
|
+
const [search, prop] = match;
|
|
78
|
+
dest = dest.replace(search, parts[prop]);
|
|
79
79
|
}
|
|
80
|
-
dest = path.resolve(dest)
|
|
80
|
+
dest = path.resolve(dest);
|
|
81
81
|
|
|
82
82
|
// If output was not a template, assume dest is a directory when using
|
|
83
83
|
// batch processing.
|
|
84
|
-
const outputAssumeDir = dest === path.resolve(output) && isBatch
|
|
84
|
+
const outputAssumeDir = dest === path.resolve(output) && isBatch;
|
|
85
85
|
if (outputAssumeDir || isDirectory.sync(dest)) {
|
|
86
|
-
const defaultExt = path.extname(src)
|
|
87
|
-
const desiredExt = transformer.options.formatOut
|
|
86
|
+
const defaultExt = path.extname(src);
|
|
87
|
+
const desiredExt = transformer.options.formatOut;
|
|
88
88
|
dest = path.format({
|
|
89
89
|
dir: dest,
|
|
90
90
|
name: path.basename(src, defaultExt),
|
|
91
|
-
ext: desiredExt in EXTENSIONS ? EXTENSIONS[desiredExt] : defaultExt
|
|
92
|
-
})
|
|
91
|
+
ext: desiredExt in EXTENSIONS ? EXTENSIONS[desiredExt] : defaultExt,
|
|
92
|
+
});
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
// Write, attach info and return.
|
|
96
|
-
fs.createReadStream(src).pipe(transformer)
|
|
96
|
+
fs.createReadStream(src).pipe(transformer);
|
|
97
97
|
return transformer
|
|
98
98
|
.toFile(dest)
|
|
99
|
-
.then((info) => Object.assign(info, { src, path: dest }))
|
|
100
|
-
})
|
|
101
|
-
return Promise.all(promises)
|
|
99
|
+
.then((info) => Object.assign(info, { src, path: dest }));
|
|
100
|
+
});
|
|
101
|
+
return Promise.all(promises);
|
|
102
102
|
},
|
|
103
103
|
|
|
104
104
|
// Convert a stream.
|
|
105
105
|
stream: (inStream, outStream, options) => {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const transformer = queue.drain(sharp(options))
|
|
106
|
+
// Create pipeline.
|
|
107
|
+
const transformer = queue.drain(sharp(options));
|
|
109
108
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
109
|
+
// Gather return value.
|
|
110
|
+
const info = {};
|
|
111
|
+
transformer.on("info", (_info) => Object.assign(info, _info));
|
|
113
112
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
outStream.on('finish', () => resolve(info))
|
|
119
|
-
})
|
|
120
|
-
}
|
|
121
|
-
}
|
|
113
|
+
// Pipe, and return as promise.
|
|
114
|
+
return pipeline(inStream, transformer, outStream).then(() => info);
|
|
115
|
+
},
|
|
116
|
+
};
|
package/lib/index.js
CHANGED
|
@@ -22,37 +22,41 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
// Strict mode.
|
|
25
|
-
|
|
25
|
+
"use strict";
|
|
26
26
|
|
|
27
27
|
// Package modules.
|
|
28
|
-
const pick = require(
|
|
28
|
+
const pick = require("lodash.pick");
|
|
29
29
|
|
|
30
30
|
// Local modules.
|
|
31
|
-
const cli = require(
|
|
32
|
-
const convert = require(
|
|
31
|
+
const cli = require("./cli");
|
|
32
|
+
const convert = require("./convert");
|
|
33
33
|
|
|
34
34
|
// Exports.
|
|
35
|
-
module.exports = (args, options = {
|
|
36
|
-
const logger = options.logger || console // Cast.
|
|
35
|
+
module.exports = (args, options = {}) => {
|
|
36
|
+
const logger = options.logger || console; // Cast.
|
|
37
37
|
|
|
38
38
|
// Parse arguments and handle i/o.
|
|
39
|
-
return cli
|
|
40
|
-
.
|
|
41
|
-
|
|
39
|
+
return cli
|
|
40
|
+
.parse(args)
|
|
41
|
+
.then((argv) => {
|
|
42
|
+
const options = pick(argv, cli.inputOptions);
|
|
42
43
|
if (argv.input) {
|
|
43
|
-
return convert.files(argv.input, argv.output, options)
|
|
44
|
+
return convert.files(argv.input, argv.output, options);
|
|
44
45
|
}
|
|
45
|
-
return convert.stream(process.stdin, process.stdout, options)
|
|
46
|
+
return convert.stream(process.stdin, process.stdout, options);
|
|
47
|
+
})
|
|
48
|
+
.then((output) => {
|
|
49
|
+
const info = Array.isArray(output) ? output : [output];
|
|
50
|
+
info.forEach((file) => logger.log(file.path));
|
|
46
51
|
})
|
|
47
|
-
.then((output) => output.map((file) => logger.log(file.path)))
|
|
48
52
|
.catch((err) => {
|
|
49
53
|
if (err instanceof Error) {
|
|
50
|
-
logger.error(err.message)
|
|
51
|
-
logger.error()
|
|
52
|
-
logger.error(
|
|
53
|
-
process.exitCode = 1
|
|
54
|
+
logger.error(err.message);
|
|
55
|
+
logger.error();
|
|
56
|
+
logger.error("Specify --help for available options");
|
|
57
|
+
process.exitCode = 1;
|
|
54
58
|
} else {
|
|
55
|
-
logger.log(err)
|
|
59
|
+
logger.log(err);
|
|
56
60
|
}
|
|
57
|
-
})
|
|
58
|
-
}
|
|
61
|
+
});
|
|
62
|
+
};
|
package/lib/queue.js
CHANGED
|
@@ -22,23 +22,24 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
// Strict mode.
|
|
25
|
-
|
|
25
|
+
"use strict";
|
|
26
26
|
|
|
27
27
|
// Configure.
|
|
28
|
-
const queue = []
|
|
28
|
+
const queue = [];
|
|
29
29
|
|
|
30
30
|
// Extend object.
|
|
31
31
|
Object.defineProperties(queue, {
|
|
32
32
|
// Add drain handler.
|
|
33
33
|
drain: {
|
|
34
|
-
value: (initialValue) =>
|
|
34
|
+
value: (initialValue) =>
|
|
35
|
+
queue.reduce((acc, [, cb]) => cb(acc), initialValue),
|
|
35
36
|
},
|
|
36
37
|
|
|
37
38
|
// Add pipeline getter.
|
|
38
39
|
pipeline: {
|
|
39
|
-
get: () => queue.map(([value]) => value)
|
|
40
|
-
}
|
|
41
|
-
})
|
|
40
|
+
get: () => queue.map(([value]) => value),
|
|
41
|
+
},
|
|
42
|
+
});
|
|
42
43
|
|
|
43
44
|
// Exports.
|
|
44
|
-
module.exports = queue
|
|
45
|
+
module.exports = queue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@depup/sharp-cli",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0-depup.0",
|
|
4
4
|
"description": "CLI for sharp. (with updated dependencies)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sharp-cli",
|
|
@@ -27,26 +27,25 @@
|
|
|
27
27
|
},
|
|
28
28
|
"main": "lib/",
|
|
29
29
|
"scripts": {
|
|
30
|
-
"
|
|
30
|
+
"format": "prettier . --write",
|
|
31
|
+
"pretest": "prettier . --check",
|
|
31
32
|
"test": "nyc mocha",
|
|
32
33
|
"posttest": "nyc report --reporter=lcov"
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
35
|
-
"bubble-stream-error": "1.0.x",
|
|
36
36
|
"glob": "^13.0.6",
|
|
37
37
|
"is-directory": "^0.3.1",
|
|
38
38
|
"lodash.pick": "^4.4.0",
|
|
39
|
-
"sharp": "^0.
|
|
40
|
-
"yargs": "^18.
|
|
39
|
+
"sharp": "^0.35.3",
|
|
40
|
+
"yargs": "^18.1.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"fs-extra": "11.3.x",
|
|
44
44
|
"mocha": "10.8.x",
|
|
45
45
|
"must": "0.13.x",
|
|
46
46
|
"nyc": "17.1.x",
|
|
47
|
+
"prettier": "3.9.6",
|
|
47
48
|
"sinon": "21.0.x",
|
|
48
|
-
"snazzy": "9.0.x",
|
|
49
|
-
"standard": "17.1.x",
|
|
50
49
|
"tempy": "1.0.x"
|
|
51
50
|
},
|
|
52
51
|
"engines": {
|
|
@@ -55,7 +54,7 @@
|
|
|
55
54
|
"depup": {
|
|
56
55
|
"changes": {
|
|
57
56
|
"glob": {
|
|
58
|
-
"from": "
|
|
57
|
+
"from": "10.5.x",
|
|
59
58
|
"to": "^13.0.6"
|
|
60
59
|
},
|
|
61
60
|
"is-directory": {
|
|
@@ -67,18 +66,18 @@
|
|
|
67
66
|
"to": "^4.4.0"
|
|
68
67
|
},
|
|
69
68
|
"sharp": {
|
|
70
|
-
"from": "0.34.
|
|
71
|
-
"to": "^0.
|
|
69
|
+
"from": "0.34.5",
|
|
70
|
+
"to": "^0.35.3"
|
|
72
71
|
},
|
|
73
72
|
"yargs": {
|
|
74
73
|
"from": "^17.6.2",
|
|
75
|
-
"to": "^18.
|
|
74
|
+
"to": "^18.1.0"
|
|
76
75
|
}
|
|
77
76
|
},
|
|
78
77
|
"depsUpdated": 5,
|
|
79
78
|
"originalPackage": "sharp-cli",
|
|
80
|
-
"originalVersion": "5.
|
|
81
|
-
"processedAt": "2026-
|
|
79
|
+
"originalVersion": "5.3.0",
|
|
80
|
+
"processedAt": "2026-08-16T00:30:13.494Z",
|
|
82
81
|
"smokeTest": "failed"
|
|
83
82
|
}
|
|
84
83
|
}
|