@depup/sharp-cli 5.2.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 (46) hide show
  1. package/.gitattributes +1 -0
  2. package/CHANGELOG.md +336 -0
  3. package/LICENSE.txt +20 -0
  4. package/README.md +35 -0
  5. package/bin/cli.js +32 -0
  6. package/changes.json +26 -0
  7. package/cmd/channel-manipulation/bandbool.js +61 -0
  8. package/cmd/channel-manipulation/ensure-alpha.js +62 -0
  9. package/cmd/channel-manipulation/extract-channel.js +61 -0
  10. package/cmd/channel-manipulation/join-channel.js +60 -0
  11. package/cmd/channel-manipulation/remove-alpha.js +49 -0
  12. package/cmd/colour-manipulation/greyscale.js +50 -0
  13. package/cmd/colour-manipulation/pipeline-colourspace.js +63 -0
  14. package/cmd/colour-manipulation/tint.js +58 -0
  15. package/cmd/colour-manipulation/tocolourspace.js +63 -0
  16. package/cmd/compositing/composite.js +187 -0
  17. package/cmd/operations/affine.js +110 -0
  18. package/cmd/operations/blur.js +87 -0
  19. package/cmd/operations/boolean.js +66 -0
  20. package/cmd/operations/clahe.js +82 -0
  21. package/cmd/operations/convolve.js +103 -0
  22. package/cmd/operations/flatten.js +63 -0
  23. package/cmd/operations/flip.js +49 -0
  24. package/cmd/operations/flop.js +49 -0
  25. package/cmd/operations/gamma.js +66 -0
  26. package/cmd/operations/linear.js +73 -0
  27. package/cmd/operations/median.js +62 -0
  28. package/cmd/operations/modulate.js +78 -0
  29. package/cmd/operations/negate.js +60 -0
  30. package/cmd/operations/normalise.js +69 -0
  31. package/cmd/operations/recomb.js +74 -0
  32. package/cmd/operations/rotate.js +72 -0
  33. package/cmd/operations/sharpen.js +109 -0
  34. package/cmd/operations/threshold.js +73 -0
  35. package/cmd/operations/unflatten.js +49 -0
  36. package/cmd/output.js +125 -0
  37. package/cmd/resizing/extend.js +102 -0
  38. package/cmd/resizing/extract.js +79 -0
  39. package/cmd/resizing/resize.js +124 -0
  40. package/cmd/resizing/trim.js +82 -0
  41. package/lib/cli.js +800 -0
  42. package/lib/constants.js +55 -0
  43. package/lib/convert.js +121 -0
  44. package/lib/index.js +58 -0
  45. package/lib/queue.js +44 -0
  46. package/package.json +84 -0
package/cmd/output.js ADDED
@@ -0,0 +1,125 @@
1
+ /*!
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2019 Mark van Seventer
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ * this software and associated documentation files (the "Software"), to deal in
8
+ * the Software without restriction, including without limitation the rights to
9
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10
+ * the Software, and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ // @see https://sharp.pixelplumbing.com/api-output#tile
25
+
26
+ // Strict mode.
27
+ 'use strict'
28
+
29
+ // Package modules.
30
+ const pick = require('lodash.pick')
31
+
32
+ // Local modules.
33
+ const constants = require('../lib/constants')
34
+ const queue = require('../lib/queue')
35
+
36
+ // Configure.
37
+ const positionals = {
38
+ size: {
39
+ desc: 'Tile size in pixels',
40
+ defaultDescription: 256,
41
+ type: 'number'
42
+ }
43
+ }
44
+
45
+ const options = {
46
+ angle: {
47
+ choices: [0, 90, 180, 270],
48
+ defaultDescription: '0',
49
+ desc: 'Tile angle of rotation'
50
+ },
51
+ background: {
52
+ defaultDescription: 'rgb(255, 255, 255, 1)',
53
+ desc: 'Background colour, parsed by the color module',
54
+ type: 'string'
55
+ },
56
+ basename: {
57
+ desc: 'The name of the directory within the zip file',
58
+ type: 'string'
59
+ },
60
+ center: {
61
+ alias: 'centre',
62
+ desc: 'Center images in tile',
63
+ type: 'boolean'
64
+ },
65
+ container: {
66
+ choices: constants.CONTAINER,
67
+ defaultDescription: 'fs',
68
+ desc: 'Tile container'
69
+ },
70
+ depth: {
71
+ choices: constants.DEPTH,
72
+ defaultDescription: 'auto',
73
+ desc: 'Pyramid depth'
74
+ },
75
+ id: {
76
+ defaultDescription: 'https://example.com/iiif',
77
+ desc: 'Set the @id/id attribute of info.json',
78
+ type: 'string'
79
+ },
80
+ layout: {
81
+ choices: constants.LAYOUT,
82
+ defaultDescription: 'dz',
83
+ desc: 'Filesystem layout'
84
+ },
85
+ overlap: {
86
+ desc: 'Tile overlap in pixels',
87
+ defaultDescription: '0',
88
+ type: 'number'
89
+ },
90
+ skipBlanks: {
91
+ defaultDescription: -1,
92
+ desc: 'Threshold to skip tile generation',
93
+ type: 'number'
94
+ }
95
+ }
96
+ const optionNames = Object.keys(options)
97
+
98
+ // Command builder.
99
+ const builder = (yargs) => {
100
+ return yargs
101
+ .strict()
102
+ .example('$0 tile 512', 'output.dz is the Deep Zoom XML definition, output_files contains 512×512 tiles grouped by zoom level')
103
+ .epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-output#tile')
104
+ .positional('size', positionals.size)
105
+ .options(options)
106
+ .group(optionNames, 'Command Options')
107
+ }
108
+
109
+ // Command handler.
110
+ const handler = (args) => {
111
+ return queue.push(['tile', (sharp) => {
112
+ return sharp.tile({
113
+ size: args.size,
114
+ ...pick(args, optionNames)
115
+ })
116
+ }])
117
+ }
118
+
119
+ // Exports.
120
+ module.exports = {
121
+ command: 'tile [size]',
122
+ describe: 'Use tile-based deep zoom (image pyramid) output',
123
+ builder,
124
+ handler
125
+ }
@@ -0,0 +1,102 @@
1
+ /*!
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2019 Mark van Seventer
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ * this software and associated documentation files (the "Software"), to deal in
8
+ * the Software without restriction, including without limitation the rights to
9
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10
+ * the Software, and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ // @see https://sharp.dimens.io/api-resize#extend
25
+
26
+ // Strict mode.
27
+ 'use strict'
28
+
29
+ // Package modules.
30
+ const pick = require('lodash.pick')
31
+
32
+ // Local modules.
33
+ const constants = require('../../lib/constants')
34
+ const queue = require('../../lib/queue')
35
+
36
+ // Configure.
37
+ const positionals = {
38
+ bottom: {
39
+ desc: 'Pixel count to add to the bottom edge',
40
+ type: 'number'
41
+ },
42
+ left: {
43
+ desc: 'Pixel count to add to the left edge',
44
+ type: 'number'
45
+ },
46
+ right: {
47
+ desc: 'Pixel count to add to the right edge',
48
+ type: 'number'
49
+ },
50
+ top: {
51
+ desc: 'Pixel count to add to the top edge',
52
+ type: 'number'
53
+ }
54
+ }
55
+
56
+ const options = {
57
+ background: {
58
+ defaultDescription: 'rgba(0, 0, 0, 1)',
59
+ desc: 'Background colour, parsed by the color module',
60
+ type: 'string'
61
+ },
62
+ extendWith: {
63
+ choices: constants.EXTEND_WITH,
64
+ default: 'background',
65
+ desc: 'Populate new pixels using this method'
66
+ }
67
+ }
68
+
69
+ // Command builder.
70
+ const builder = (yargs) => {
71
+ const optionNames = Object.keys(options)
72
+ return yargs
73
+ .strict()
74
+ .example('$0 extend 10 20 10 10 --background rgba(0,0,0,0)', 'Add 10 transparent pixels to the top, left, and right edges, and 20 to the bottom edge')
75
+ .example('$0 extend 0 10 0 0 --background red', 'Add 10 red pixels to the bottom edge.')
76
+ .epilog('For more information on available options, please visit https://sharp.dimens.io/api-resize#extend')
77
+ .positional('top', positionals.top)
78
+ .positional('bottom', positionals.bottom)
79
+ .positional('left', positionals.left)
80
+ .positional('right', positionals.right)
81
+ .options(options)
82
+ .group(optionNames, 'Command Options')
83
+ }
84
+
85
+ // Command handler.
86
+ const handler = (args) => {
87
+ return queue.push(['extend', (sharp) => {
88
+ return sharp.extend({
89
+ background: args.background,
90
+ extendWith: args.extendWith,
91
+ ...pick(args, Object.keys(positionals))
92
+ })
93
+ }])
94
+ }
95
+
96
+ // Exports.
97
+ module.exports = {
98
+ command: 'extend <top> <bottom> <left> <right>',
99
+ describe: 'Extends/pads the edges of the image with the provided background colour',
100
+ builder,
101
+ handler
102
+ }
@@ -0,0 +1,79 @@
1
+ /*!
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2019 Mark van Seventer
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ * this software and associated documentation files (the "Software"), to deal in
8
+ * the Software without restriction, including without limitation the rights to
9
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10
+ * the Software, and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ // @see https://sharp.dimens.io/api-resize#extract
25
+
26
+ // Strict mode.
27
+ 'use strict'
28
+
29
+ // Package modules.
30
+ const pick = require('lodash.pick')
31
+
32
+ // Local modules.
33
+ const queue = require('../../lib/queue')
34
+
35
+ // Configure.
36
+ const positionals = {
37
+ height: {
38
+ desc: 'Height of region to extract',
39
+ type: 'number'
40
+ },
41
+ left: {
42
+ desc: 'Zero-indexed offset from left edge',
43
+ type: 'number'
44
+ },
45
+ top: {
46
+ desc: 'Zero-indexed offset from top edge',
47
+ type: 'number'
48
+ },
49
+ width: {
50
+ desc: 'Width of region to extract',
51
+ type: 'number'
52
+ }
53
+ }
54
+
55
+ // Command builder.
56
+ const builder = (yargs) => {
57
+ return yargs
58
+ .strict()
59
+ .epilog('For more information on available options, please visit https://sharp.dimens.io/api-resize#extract')
60
+ .positional('top', positionals.top)
61
+ .positional('left', positionals.left)
62
+ .positional('width', positionals.width)
63
+ .positional('height', positionals.height)
64
+ }
65
+
66
+ // Command handler.
67
+ const handler = (args) => {
68
+ return queue.push(['extract', (sharp) => {
69
+ return sharp.extract(pick(args, Object.keys(positionals)))
70
+ }])
71
+ }
72
+
73
+ // Exports.
74
+ module.exports = {
75
+ command: 'extract <top> <left> <width> <height>',
76
+ describe: 'Extract a region of the image',
77
+ builder,
78
+ handler
79
+ }
@@ -0,0 +1,124 @@
1
+ /*!
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2019 Mark van Seventer
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ * this software and associated documentation files (the "Software"), to deal in
8
+ * the Software without restriction, including without limitation the rights to
9
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10
+ * the Software, and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ // @see https://sharp.pixelplumbing.com/api-resize/
25
+
26
+ // Strict mode.
27
+ 'use strict'
28
+
29
+ // Package modules.
30
+ const pick = require('lodash.pick')
31
+
32
+ // Local modules.
33
+ const constants = require('../../lib/constants')
34
+ const queue = require('../../lib/queue')
35
+
36
+ // Configure.
37
+ const positionals = {
38
+ width: {
39
+ default: null,
40
+ desc: 'Pixels wide the resultant image should be',
41
+ type: 'number'
42
+ },
43
+ height: {
44
+ default: null,
45
+ desc: 'Pixels high the resultant image should be',
46
+ type: 'number'
47
+ }
48
+ }
49
+
50
+ const options = {
51
+ background: {
52
+ defaultDescription: 'rgba(0, 0, 0, 1)',
53
+ desc: 'Background colour when fit is contain, parsed by the color module.',
54
+ type: 'string'
55
+ },
56
+ fastShrinkOnLoad: {
57
+ defaultDescription: true,
58
+ desc: 'Take greater advantage of the JPEG and WebP shrink-on-load feature',
59
+ type: 'boolean'
60
+ },
61
+ fit: {
62
+ choices: constants.FIT,
63
+ defaultDescription: 'cover',
64
+ desc: 'How the image should be resized to fit both provided dimensions'
65
+ },
66
+ kernel: {
67
+ choices: constants.KERNEL,
68
+ defaultDescription: 'lanczos3',
69
+ desc: 'The kernel to use for image reduction and the inferred interpolator to use for upsampling'
70
+ },
71
+ 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'
75
+ },
76
+ withoutEnlargement: {
77
+ desc: 'Do not enlarge if the width or height are already less than the specified dimensions',
78
+ type: 'boolean'
79
+ },
80
+ 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)
86
+
87
+ // Command builder.
88
+ const builder = (yargs) => {
89
+ return yargs
90
+ .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 => {
101
+ if (argv.width === null && argv.height === null) {
102
+ throw new Error('Expected at least one of width and height positionals')
103
+ }
104
+ return true
105
+ })
106
+ .options(options)
107
+ .group(optionNames, 'Command Options')
108
+ }
109
+
110
+ // Command handler.
111
+ const handler = (args) => {
112
+ // @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
+ }
117
+
118
+ // Exports.
119
+ module.exports = {
120
+ command: 'resize [width] [height]',
121
+ describe: 'Resize image to width, height, or width × height',
122
+ builder,
123
+ handler
124
+ }
@@ -0,0 +1,82 @@
1
+ /*!
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2019 Mark van Seventer
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ * this software and associated documentation files (the "Software"), to deal in
8
+ * the Software without restriction, including without limitation the rights to
9
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10
+ * the Software, and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
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')
31
+
32
+ // Configure.
33
+ const positionals = {
34
+ threshold: {
35
+ desc: 'The allowed difference from the top-left pixel',
36
+ defaultDescription: 10,
37
+ type: 'number'
38
+ }
39
+ }
40
+
41
+ const options = {
42
+ background: {
43
+ defaultDescription: 'top-left pixel',
44
+ desc: 'Background colour, parsed by the color module',
45
+ type: 'string'
46
+ },
47
+ lineArt: {
48
+ default: false,
49
+ desc: 'Does the input more closely resemble line art rather than being photographic',
50
+ type: 'boolean'
51
+ }
52
+ }
53
+
54
+ // Command builder.
55
+ const builder = (yargs) => {
56
+ const optionNames = Object.keys(options)
57
+ return yargs
58
+ .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)
65
+ .options(options)
66
+ .group(optionNames, 'Command Options')
67
+ }
68
+
69
+ // Command handler.
70
+ const handler = (args) => {
71
+ return queue.push(['trim', (sharp) => {
72
+ return sharp.trim({ background: args.background, lineArt: args.lineArt, threshold: args.threshold })
73
+ }])
74
+ }
75
+
76
+ // 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',
80
+ builder,
81
+ handler
82
+ }