@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,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
- const constants = require('../../lib/constants')
34
- const queue = require('../../lib/queue')
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: 'Pixels wide the resultant image should be',
41
- type: 'number'
34
+ desc: "Pixels wide the resultant image should be",
35
+ type: "number",
42
36
  },
43
37
  height: {
44
38
  default: null,
45
- desc: 'Pixels high the resultant image should be',
46
- type: 'number'
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: 'rgba(0, 0, 0, 1)',
53
- desc: 'Background colour when fit is contain, parsed by the color module.',
54
- type: 'string'
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: 'Take greater advantage of the JPEG and WebP shrink-on-load feature',
59
- type: 'boolean'
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: 'cover',
64
- desc: 'How the image should be resized to fit both provided dimensions'
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: 'lanczos3',
69
- desc: 'The kernel to use for image reduction and the inferred interpolator to use for upsampling'
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: [...constants.GRAVITY, ...constants.POSITION, ...constants.STRATEGY],
73
- defaultDescription: 'centre',
74
- desc: 'Position, gravity, or strategy to use when fit is cover or contain'
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: 'Do not enlarge if the width or height are already less than the specified dimensions',
78
- type: 'boolean'
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: 'Do not reduce if the width or height are already greater than the specified dimensions',
82
- type: 'boolean'
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('$0 resize 100', 'The output will be 100 pixels wide, auto-scaled height')
92
- .example('$0 resize --height 100', 'The output will be 100 pixels high, auto-scaled width')
93
- .example('$0 resize 200 300 --background rgba(255,255,255,0.5) --fit contain --kernel nearest --position "right top"', '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')
94
- .example('$0 resize 200 200 --fit cover --position entropy', 'The output will be a 200px square auto-cropped image')
95
- .example('$0 resize 200 200 --withoutEnlargement', 'The output will be no wider and no higher than 200 pixels, and no larger than the input image')
96
- .example('$0 resize 200 200 --withoutReduction', 'The output will be at least 200 pixels wide and 200 pixels high while maintaining aspect ratio, and no smaller than the input image')
97
- .epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-resize/')
98
- .positional('width', positionals.width)
99
- .positional('height', positionals.height)
100
- .check(argv => {
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('Expected at least one of width and height positionals')
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, 'Command Options')
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(['resize', (sharp) => {
114
- return sharp.resize(args.width, args.height, pick(args, optionNames))
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
- module.exports = {
120
- command: 'resize [width] [height]',
121
- describe: 'Resize image to width, height, or width × height',
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
+ };
@@ -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.dimens.io/api-resize#trim
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: 'The allowed difference from the top-left pixel',
29
+ desc: "The allowed difference from the top-left pixel",
36
30
  defaultDescription: 10,
37
- type: 'number'
38
- }
39
- }
31
+ type: "number",
32
+ },
33
+ };
40
34
 
41
35
  const options = {
42
36
  background: {
43
- defaultDescription: 'top-left pixel',
44
- desc: 'Background colour, parsed by the color module',
45
- type: 'string'
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: 'Does the input more closely resemble line art rather than being photographic',
50
- type: 'boolean'
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('$0 trim', 'Trim pixels with a colour similar to that of the top-left pixel')
60
- .example('$0 trim 0', 'Trim pixels with the exact same colour as that of the top-left pixel')
61
- .example('$0 trim --background "#FF0000"', 'Trim pixels with a similar colour to red')
62
- .example('$0 trim 42 --background yellow', 'Trim all "yellow-ish" pixels')
63
- .epilog('For more information on available options, please visit https://sharp.dimens.io/api-resize#trim')
64
- .positional('threshold', positionals.threshold)
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, 'Command Options')
67
- }
80
+ .group(optionNames, "Command Options");
81
+ };
68
82
 
69
83
  // Command handler.
70
84
  const handler = (args) => {
71
- return queue.push(['trim', (sharp) => {
72
- return sharp.trim({ background: args.background, lineArt: args.lineArt, threshold: args.threshold })
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
- module.exports = {
78
- command: 'trim [threshold]',
79
- describe: 'Trim pixels from all edges that contain values similar to the given background color, which defaults to that of the top-left pixel',
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
- // Strict mode.
25
- 'use strict'
24
+ // Package modules.
25
+ import js from "@eslint/js";
26
+ import globals from "globals";
27
+ import { defineConfig, globalIgnores } from "eslint/config";
26
28
 
27
- // Configure.
28
- const queue = []
29
+ // Exports.
30
+ export default defineConfig([
31
+ globalIgnores(["coverage/**", ".nyc_output/**"]),
32
+ js.configs.recommended,
29
33
 
30
- // Extend object.
31
- Object.defineProperties(queue, {
32
- // Add drain handler.
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
- // Add pipeline getter.
38
- pipeline: {
39
- get: () => queue.map(([value]) => value)
40
- }
41
- })
42
-
43
- // Exports.
44
- module.exports = queue
39
+ {
40
+ files: ["test/**/*.js"],
41
+ languageOptions: {
42
+ globals: {
43
+ ...globals.node,
44
+ ...globals.mocha,
45
+ },
46
+ },
47
+ },
48
+ ]);