@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.
Files changed (50) hide show
  1. package/.github/workflows/ci.yml +30 -0
  2. package/.prettierignore +2 -0
  3. package/.prettierrc +1 -0
  4. package/CHANGELOG.md +40 -8
  5. package/README.md +6 -9
  6. package/bin/cli.js +5 -5
  7. package/changes.json +5 -17
  8. package/cmd/channel-manipulation/bandbool.js +24 -19
  9. package/cmd/channel-manipulation/ensure-alpha.js +27 -22
  10. package/cmd/channel-manipulation/extract-channel.js +23 -19
  11. package/cmd/channel-manipulation/join-channel.js +19 -20
  12. package/cmd/channel-manipulation/remove-alpha.js +12 -15
  13. package/cmd/colour-manipulation/greyscale.js +16 -16
  14. package/cmd/colour-manipulation/pipeline-colourspace.js +26 -22
  15. package/cmd/colour-manipulation/tint.js +17 -19
  16. package/cmd/colour-manipulation/tocolourspace.js +22 -21
  17. package/cmd/compositing/composite.js +133 -102
  18. package/cmd/operations/affine.js +57 -51
  19. package/cmd/operations/blur.js +44 -41
  20. package/cmd/operations/boolean.js +22 -21
  21. package/cmd/operations/clahe.js +37 -37
  22. package/cmd/operations/convolve.js +52 -48
  23. package/cmd/operations/dilate.js +58 -0
  24. package/cmd/operations/erode.js +58 -0
  25. package/cmd/operations/flatten.js +23 -24
  26. package/cmd/operations/flip.js +12 -15
  27. package/cmd/operations/flop.js +12 -15
  28. package/cmd/operations/gamma.js +26 -25
  29. package/cmd/operations/linear.js +30 -29
  30. package/cmd/operations/median.js +18 -22
  31. package/cmd/operations/modulate.js +42 -31
  32. package/cmd/operations/negate.js +17 -20
  33. package/cmd/operations/normalise.js +28 -25
  34. package/cmd/operations/recomb.js +34 -32
  35. package/cmd/operations/rotate.js +31 -29
  36. package/cmd/operations/sharpen.js +49 -45
  37. package/cmd/operations/threshold.js +29 -29
  38. package/cmd/operations/unflatten.js +14 -16
  39. package/cmd/output.js +61 -56
  40. package/cmd/resizing/extend.js +55 -49
  41. package/cmd/resizing/extract.js +32 -33
  42. package/cmd/resizing/resize.js +79 -56
  43. package/cmd/resizing/trim.js +59 -36
  44. package/{lib/queue.js → eslint.config.mjs} +21 -17
  45. package/lib/cli.js +637 -383
  46. package/lib/constants.js +24 -18
  47. package/lib/convert.js +106 -73
  48. package/lib/index.js +56 -23
  49. package/lib/utils.js +50 -0
  50. package/package.json +27 -37
@@ -23,51 +23,52 @@
23
23
 
24
24
  // @see https://sharp.pixelplumbing.com/api-operation#linear
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
  multiplier: {
35
- desc: 'Multiplier',
29
+ desc: "Multiplier",
36
30
  default: 1.0,
37
- type: 'number'
38
- }
39
- }
31
+ type: "number",
32
+ },
33
+ };
40
34
 
41
35
  const options = {
42
36
  offset: {
43
- desc: 'Offset',
44
- type: 'array'
45
- }
46
- }
37
+ desc: "Offset",
38
+ type: "array",
39
+ },
40
+ };
47
41
 
48
42
  // Command builder.
49
43
  const builder = (yargs) => {
50
- const optionNames = Object.keys(options)
44
+ const optionNames = Object.keys(options);
51
45
  return yargs
52
46
  .strict()
53
- .example('$0 linear 0.5 --offset 2')
54
- .example('$0 linear 0.25 0.5 0.75 --offset 150 100 50')
55
- .epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-operation#linear')
56
- .positional('multiplier', positionals.multiplier)
47
+ .example("$0 linear 0.5 --offset 2")
48
+ .example("$0 linear 0.25 0.5 0.75 --offset 150 100 50")
49
+ .epilog(
50
+ "For more information on available options, please visit https://sharp.pixelplumbing.com/api-operation#linear",
51
+ )
52
+ .positional("multiplier", positionals.multiplier)
57
53
  .options(options)
58
- .group(optionNames, 'Command Options')
59
- }
54
+ .group(optionNames, "Command Options");
55
+ };
60
56
 
61
57
  // Command handler.
62
58
  const handler = (args) => {
63
- const multiplier = args.multiplier.length === 1 ? args.multiplier[0] : args.multiplier
64
- return queue.push(['linear', (sharp) => sharp.linear(multiplier, args.offset)])
65
- }
59
+ const multiplier =
60
+ args.multiplier.length === 1 ? args.multiplier[0] : args.multiplier;
61
+ return args["#queue"].push([
62
+ "linear",
63
+ (sharp) => sharp.linear(multiplier, args.offset),
64
+ ]);
65
+ };
66
66
 
67
67
  // Exports.
68
- module.exports = {
69
- command: 'linear [multiplier..]',
70
- describe: 'Apply the linear formula a × input + b to the image to adjust image levels',
68
+ export default {
69
+ command: "linear [multiplier..]",
70
+ describe:
71
+ "Apply the linear formula a × input + b to the image to adjust image levels",
71
72
  builder,
72
- handler
73
- }
73
+ handler,
74
+ };
@@ -23,40 +23,36 @@
23
23
 
24
24
  // @see https://sharp.pixelplumbing.com/api-operation#median
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
  size: {
35
- desc: 'Square mask size',
29
+ desc: "Square mask size",
36
30
  defaultDescription: 3,
37
- type: 'number'
38
- }
39
- }
31
+ type: "number",
32
+ },
33
+ };
40
34
 
41
35
  // Command builder.
42
36
  const builder = (yargs) => {
43
37
  return yargs
44
38
  .strict()
45
- .example('$0 median')
46
- .example('$0 median 5')
47
- .epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-operation#median')
48
- .positional('size', positionals.size)
49
- }
39
+ .example("$0 median")
40
+ .example("$0 median 5")
41
+ .epilog(
42
+ "For more information on available options, please visit https://sharp.pixelplumbing.com/api-operation#median",
43
+ )
44
+ .positional("size", positionals.size);
45
+ };
50
46
 
51
47
  // Command handler.
52
48
  const handler = (args) => {
53
- return queue.push(['median', (sharp) => sharp.median(args.size)])
54
- }
49
+ return args["#queue"].push(["median", (sharp) => sharp.median(args.size)]);
50
+ };
55
51
 
56
52
  // Exports.
57
- module.exports = {
58
- command: 'median [size]',
59
- describe: 'Apply median filter',
53
+ export default {
54
+ command: "median [size]",
55
+ describe: "Apply median filter",
60
56
  builder,
61
- handler
62
- }
57
+ handler,
58
+ };
@@ -23,56 +23,67 @@
23
23
 
24
24
  // @see http://sharp.pixelplumbing.com/api-operation#modulate
25
25
 
26
- // Strict mode.
27
- 'use strict'
28
-
29
- // Package modules.
30
- const pick = require('lodash.pick')
31
-
32
26
  // Local modules.
33
- const queue = require('../../lib/queue')
27
+ import { pick } from "../../lib/utils.js";
34
28
 
35
29
  // Configure.
36
30
  const options = {
37
31
  brightness: {
38
- desc: 'Brightness multiplier',
39
- type: 'number'
32
+ desc: "Brightness multiplier",
33
+ nargs: 1,
34
+ type: "number",
40
35
  },
41
36
  hue: {
42
- desc: 'Degrees for hue rotation',
43
- type: 'number'
37
+ desc: "Degrees for hue rotation",
38
+ nargs: 1,
39
+ type: "number",
44
40
  },
45
41
  lightness: {
46
- desc: 'Lightness addend',
47
- type: 'number'
42
+ desc: "Lightness addend",
43
+ nargs: 1,
44
+ type: "number",
48
45
  },
49
46
  saturation: {
50
- desc: 'Saturation multiplier',
51
- type: 'number'
52
- }
53
- }
54
- const optionNames = Object.keys(options)
47
+ desc: "Saturation multiplier",
48
+ nargs: 1,
49
+ type: "number",
50
+ },
51
+ };
52
+ const optionNames = Object.keys(options);
55
53
 
56
54
  // Command builder.
57
55
  const builder = (yargs) => {
58
56
  return yargs
59
57
  .strict()
60
- .example('$0 modulate --brightness 2', 'Increase brightness by a factor of 2')
61
- .example('$0 modulate --hue 180', 'Hue-rotate by 180 degrees')
62
- .example('$0 modulate --lightness 50', 'Increase lightness by +50')
63
- .example('$0 modulate --brightness 0.5 --saturation 0.5 --hue 90', 'Decrease brightness and saturation while also hue-rotating by 90 degrees')
64
- .epilog('For more information on available options, please visit http://sharp.pixelplumbing.com/api-operation#modulate')
58
+ .example(
59
+ "$0 modulate --brightness 2",
60
+ "Increase brightness by a factor of 2",
61
+ )
62
+ .example("$0 modulate --hue 180", "Hue-rotate by 180 degrees")
63
+ .example("$0 modulate --lightness 50", "Increase lightness by +50")
64
+ .example(
65
+ "$0 modulate --brightness 0.5 --saturation 0.5 --hue 90",
66
+ "Decrease brightness and saturation while also hue-rotating by 90 degrees",
67
+ )
68
+ .epilog(
69
+ "For more information on available options, please visit http://sharp.pixelplumbing.com/api-operation#modulate",
70
+ )
65
71
  .options(options)
66
- .group(optionNames, 'Command Options')
67
- }
72
+ .group(optionNames, "Command Options");
73
+ };
68
74
 
69
75
  // Command handler.
70
- const handler = (args) => queue.push(['modulate', (sharp) => sharp.modulate(pick(args, optionNames))])
76
+ const handler = (args) =>
77
+ args["#queue"].push([
78
+ "modulate",
79
+ (sharp) => sharp.modulate(pick(args, optionNames)),
80
+ ]);
71
81
 
72
82
  // Exports.
73
- module.exports = {
74
- command: 'modulate',
75
- describe: 'Transforms the image using brightness, saturation, hue rotation, and lightness',
83
+ export default {
84
+ command: "modulate",
85
+ describe:
86
+ "Transforms the image using brightness, saturation, hue rotation, and lightness",
76
87
  builder,
77
- handler
78
- }
88
+ handler,
89
+ };
@@ -23,38 +23,35 @@
23
23
 
24
24
  // @see https://sharp.pixelplumbing.com/api-operation#negate
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 options = {
34
28
  alpha: {
35
- desc: 'Whether or not to negate any alpha channel',
36
- type: 'boolean'
37
- }
38
- }
29
+ desc: "Whether or not to negate any alpha channel",
30
+ type: "boolean",
31
+ },
32
+ };
39
33
 
40
34
  // Command builder.
41
35
  const builder = (yargs) => {
42
- const optionNames = Object.keys(options)
36
+ const optionNames = Object.keys(options);
43
37
  return yargs
44
38
  .strict()
45
- .example('$0 negate --no-alpha')
46
- .epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-operation#negate')
39
+ .example("$0 negate --no-alpha")
40
+ .epilog(
41
+ "For more information on available options, please visit https://sharp.pixelplumbing.com/api-operation#negate",
42
+ )
47
43
  .options(options)
48
- .group(optionNames, 'Command Options')
49
- }
44
+ .group(optionNames, "Command Options");
45
+ };
50
46
 
51
47
  // Command handler.
52
- const handler = (args) => queue.push(['negate', (sharp) => sharp.negate(args.alpha)])
48
+ const handler = (args) =>
49
+ args["#queue"].push(["negate", (sharp) => sharp.negate(args.alpha)]);
53
50
 
54
51
  // Exports.
55
- module.exports = {
56
- command: 'negate',
52
+ export default {
53
+ command: "negate",
57
54
  describe: 'Produce the "negative" of the image',
58
55
  builder,
59
- handler
60
- }
56
+ handler,
57
+ };
@@ -23,47 +23,50 @@
23
23
 
24
24
  // @see https://sharp.pixelplumbing.com/api-operation#normalise
25
25
 
26
- // Strict mode.
27
- 'use strict'
28
-
29
- // Package modules.
30
- const pick = require('lodash.pick')
31
-
32
26
  // Local modules.
33
- const queue = require('../../lib/queue')
27
+ import { pick } from "../../lib/utils.js";
34
28
 
35
29
  const options = {
36
30
  lower: {
37
31
  default: 1,
38
- desc: 'Percentile below which luminance values will be underexposed',
39
- type: 'number'
32
+ desc: "Percentile below which luminance values will be underexposed",
33
+ nargs: 1,
34
+ type: "number",
40
35
  },
41
36
  upper: {
42
37
  default: 99,
43
- desc: 'Percentile below which luminance values will be overexposed',
44
- type: 'number'
45
- }
46
- }
47
- const optionNames = Object.keys(options)
38
+ desc: "Percentile below which luminance values will be overexposed",
39
+ nargs: 1,
40
+ type: "number",
41
+ },
42
+ };
43
+ const optionNames = Object.keys(options);
48
44
 
49
45
  // Command builder.
50
46
  const builder = (yargs) => {
51
47
  return yargs
52
48
  .strict()
53
- .epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-operation#normalise')
54
- .example('$0 normalise')
49
+ .epilog(
50
+ "For more information on available options, please visit https://sharp.pixelplumbing.com/api-operation#normalise",
51
+ )
52
+ .example("$0 normalise")
55
53
  .options(options)
56
- .group(optionNames, 'Command Options')
57
- }
54
+ .group(optionNames, "Command Options");
55
+ };
58
56
 
59
57
  // Command handler.
60
- const handler = (args) => queue.push(['normalise', (sharp) => sharp.normalise(pick(args, optionNames))])
58
+ const handler = (args) =>
59
+ args["#queue"].push([
60
+ "normalise",
61
+ (sharp) => sharp.normalise(pick(args, optionNames)),
62
+ ]);
61
63
 
62
64
  // Exports.
63
- module.exports = {
64
- command: 'normalise',
65
- aliases: 'normalize',
66
- describe: 'Enhance output image contrast by stretching its luminance to cover the full dynamic range',
65
+ export default {
66
+ command: "normalise",
67
+ aliases: "normalize",
68
+ describe:
69
+ "Enhance output image contrast by stretching its luminance to cover the full dynamic range",
67
70
  builder,
68
- handler
69
- }
71
+ handler,
72
+ };
@@ -21,54 +21,56 @@
21
21
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
- // @see https://sharp.dimens.io/api-operation#recomb
25
-
26
- // Strict mode.
27
- 'use strict'
28
-
29
- // Local modules.
30
- const queue = require('../../lib/queue')
24
+ // @see https://sharp.pixelplumbing.com/api-operation#recomb
31
25
 
32
26
  // Configure.
33
27
  const placeholders = {
34
28
  matrix: {
35
- desc: 'Recombination matrix',
29
+ desc: "Recombination matrix",
36
30
  nargs: 3 * 3,
37
- type: 'number'
38
- }
39
- }
31
+ type: "number",
32
+ },
33
+ };
40
34
 
41
35
  // Command builder.
42
36
  const builder = (yargs) => {
43
37
  return yargs
44
38
  .strict()
45
- .example('$0 recomb 0.3588 0.7044 0.1368 0.2990 0.5870 0.1140 0.2392 0.4696 0.0912', 'The recomb will be applied to the output, in this case a sepia filter has been applied')
46
- .epilog('For more information on available options, please visit https://sharp.dimens.io/api-operation#recomb')
47
- .check(argv => {
39
+ .example(
40
+ "$0 recomb 0.3588 0.7044 0.1368 0.2990 0.5870 0.1140 0.2392 0.4696 0.0912",
41
+ "The recomb will be applied to the output, in this case a sepia filter has been applied",
42
+ )
43
+ .epilog(
44
+ "For more information on available options, please visit https://sharp.pixelplumbing.com/api-operation#recomb",
45
+ )
46
+ .check((argv) => {
48
47
  if (!(Array.isArray(argv.matrix) && argv.matrix.length === 9)) {
49
- throw new Error('Expected matrix positional to have 9 values')
48
+ throw new Error("Expected matrix positional to have 9 values");
50
49
  }
51
- return true
50
+ return true;
52
51
  })
53
- .positional('matrix', placeholders.matrix)
54
- }
52
+ .positional("matrix", placeholders.matrix);
53
+ };
55
54
 
56
55
  // Command handler.
57
56
  const handler = (args) => {
58
- const { matrix } = args
59
- return queue.push(['recomb', (sharp) => {
60
- return sharp.recomb([
61
- matrix.slice(0, 3),
62
- matrix.slice(3, 6),
63
- matrix.slice(6, 9)
64
- ])
65
- }])
66
- }
57
+ const { matrix } = args;
58
+ return args["#queue"].push([
59
+ "recomb",
60
+ (sharp) => {
61
+ return sharp.recomb([
62
+ matrix.slice(0, 3),
63
+ matrix.slice(3, 6),
64
+ matrix.slice(6, 9),
65
+ ]);
66
+ },
67
+ ]);
68
+ };
67
69
 
68
70
  // Exports.
69
- module.exports = {
70
- command: 'recomb <matrix..>',
71
- describe: 'Recomb the image with the specified matrix',
71
+ export default {
72
+ command: "recomb <matrix..>",
73
+ describe: "Recomb the image with the specified matrix",
72
74
  builder,
73
- handler
74
- }
75
+ handler,
76
+ };
@@ -23,50 +23,52 @@
23
23
 
24
24
  // @see https://sharp.pixelplumbing.com/api-operation#rotate
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
  angle: {
35
- defaultDescription: 'auto',
36
- desc: 'Angle of rotation',
37
- type: 'number'
38
- }
39
- }
29
+ defaultDescription: "auto",
30
+ desc: "Angle of rotation",
31
+ type: "number",
32
+ },
33
+ };
40
34
 
41
35
  const options = {
42
36
  background: {
43
- defaultDescription: '#000000',
44
- desc: 'String parsed by the color module to extract values for red, green, blue and alpha',
45
- type: 'string'
46
- }
47
- }
37
+ defaultDescription: "#000000",
38
+ desc: "String parsed by the color module to extract values for red, green, blue and alpha",
39
+ type: "string",
40
+ },
41
+ };
48
42
 
49
43
  // Command builder.
50
44
  const builder = (yargs) => {
51
- const optionNames = Object.keys(options)
45
+ const optionNames = Object.keys(options);
52
46
  return yargs
53
47
  .strict()
54
- .example('$0 rotate', 'The output will be auto-rotated using EXIF Orientation tag')
55
- .epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-operation#rotate')
56
- .positional('angle', positionals.angle)
48
+ .example(
49
+ "$0 rotate",
50
+ "The output will be auto-rotated using EXIF Orientation tag",
51
+ )
52
+ .epilog(
53
+ "For more information on available options, please visit https://sharp.pixelplumbing.com/api-operation#rotate",
54
+ )
55
+ .positional("angle", positionals.angle)
57
56
  .options(options)
58
- .group(optionNames, 'Command Options')
59
- }
57
+ .group(optionNames, "Command Options");
58
+ };
60
59
 
61
60
  // Command handler.
62
61
  const handler = (args) => {
63
- return queue.push(['rotate', (sharp) => sharp.rotate(args.angle, { background: args.background })])
64
- }
62
+ return args["#queue"].push([
63
+ "rotate",
64
+ (sharp) => sharp.rotate(args.angle, { background: args.background }),
65
+ ]);
66
+ };
65
67
 
66
68
  // Exports.
67
- module.exports = {
68
- command: 'rotate [angle]',
69
- describe: 'Rotate the output image',
69
+ export default {
70
+ command: "rotate [angle]",
71
+ describe: "Rotate the output image",
70
72
  builder,
71
- handler
72
- }
73
+ handler,
74
+ };