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