@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
@@ -0,0 +1,87 @@
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-operation#blur
25
+
26
+ // Strict mode.
27
+ 'use strict'
28
+
29
+ // Local modules.
30
+ const queue = require('../../lib/queue')
31
+
32
+ // Configure.
33
+ const positionals = {
34
+ sigma: {
35
+ desc: 'The sigma of the Gaussian mask',
36
+ defaultDescription: '1 + radius / 2',
37
+ type: 'number'
38
+ }
39
+ }
40
+
41
+ const options = {
42
+ minAmplitude: {
43
+ defaultDescription: 0.2,
44
+ desc: 'A smaller value will generate a larger, more accurate mask',
45
+ type: 'number'
46
+ },
47
+ precision: {
48
+ choices: ['approximate', 'float', 'integer'],
49
+ defaultDescription: 'integer',
50
+ desc: 'How accurate the operation should be'
51
+ }
52
+ }
53
+
54
+ // Command builder.
55
+ const builder = (yargs) => {
56
+ const optionNames = Object.keys(options)
57
+ return yargs
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)
63
+ .options(options)
64
+ .group(optionNames, 'Command Options')
65
+ }
66
+
67
+ // Command handler.
68
+ 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
+ }
80
+
81
+ // Exports.
82
+ module.exports = {
83
+ command: 'blur [sigma]',
84
+ describe: 'Blur the image',
85
+ builder,
86
+ handler
87
+ }
@@ -0,0 +1,66 @@
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-operation#boolean
25
+
26
+ // Strict mode.
27
+ 'use strict'
28
+
29
+ // Local modules.
30
+ const constants = require('../../lib/constants')
31
+ const queue = require('../../lib/queue')
32
+
33
+ // Configure.
34
+ const positionals = {
35
+ operand: {
36
+ desc: 'Path to an image file',
37
+ normalize: true,
38
+ type: 'string'
39
+ },
40
+ operator: {
41
+ choices: constants.BOOL,
42
+ desc: 'Operator to perform that bitwise operation'
43
+ }
44
+ }
45
+
46
+ // Command builder.
47
+ const builder = (yargs) => {
48
+ return yargs
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
+ }
54
+
55
+ // Command handler.
56
+ const handler = (args) => {
57
+ return queue.push(['boolean', (sharp) => sharp.boolean(args.operand, args.operator)])
58
+ }
59
+
60
+ // Exports.
61
+ module.exports = {
62
+ command: 'boolean <operand> <operator>',
63
+ describe: 'Perform a bitwise boolean operation with operand image',
64
+ builder,
65
+ handler
66
+ }
@@ -0,0 +1,82 @@
1
+ /*!
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2022 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-operation#clahe
25
+
26
+ // Strict mode.
27
+ 'use strict'
28
+
29
+ // Local modules.
30
+ const queue = require('../../lib/queue')
31
+
32
+ // Configure.
33
+ const positionals = {
34
+ height: {
35
+ desc: 'Height of the region',
36
+ type: 'number'
37
+ },
38
+ width: {
39
+ desc: 'Width of the region',
40
+ type: 'number'
41
+ }
42
+ }
43
+
44
+ const options = {
45
+ maxSlope: {
46
+ defaultDescription: 3,
47
+ desc: 'Maximum value for the slope of the cumulative histogram',
48
+ type: 'number'
49
+ }
50
+ }
51
+
52
+ // Command builder.
53
+ const builder = (yargs) => {
54
+ const optionNames = Object.keys(options)
55
+ return yargs
56
+ .strict()
57
+ .example('$0 clahe 3 3')
58
+ .epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-operation#clahe')
59
+ .positional('height', positionals.height)
60
+ .positional('width', positionals.width)
61
+ .options(options)
62
+ .group(optionNames, 'Command Options')
63
+ }
64
+
65
+ // Command handler.
66
+ const handler = (args) => {
67
+ return queue.push(['clahe', (sharp) => {
68
+ return sharp.clahe({
69
+ width: args.width,
70
+ height: args.height,
71
+ maxSlope: args.maxSlope
72
+ })
73
+ }])
74
+ }
75
+
76
+ // Exports.
77
+ module.exports = {
78
+ command: 'clahe <width> <height>',
79
+ describe: 'Perform contrast limiting adaptive histogram equalization CLAHE',
80
+ builder,
81
+ handler
82
+ }
@@ -0,0 +1,103 @@
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-operation#convolve
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 the kernel in pixels',
39
+ type: 'number'
40
+ },
41
+ kernel: {
42
+ desc: 'Array of length width × height containing the kernel values',
43
+ defaultDescription: '"-1 0 1 -2 0 2 -1 0 1"',
44
+ type: 'number'
45
+ },
46
+ width: {
47
+ desc: 'Width of the kernel in pixels',
48
+ type: 'number'
49
+ }
50
+ }
51
+ const positionalNames = Object.keys(positionals)
52
+
53
+ const options = {
54
+ scale: {
55
+ desc: 'The scale of the kernel in pixels',
56
+ defaultDescription: 'sum',
57
+ type: 'number'
58
+ },
59
+ offset: {
60
+ desc: 'The offset of the kernel in pixels',
61
+ defaultDescription: '0',
62
+ type: 'number'
63
+ }
64
+ }
65
+ const optionNames = Object.keys(options)
66
+
67
+ // Command builder.
68
+ const builder = (yargs) => {
69
+ return yargs
70
+ .strict()
71
+ .example('$0 convolve 3 3 "-1 0 1 -2 0 2 -1 0 1"', 'The output will be the convolution of the input image with the horizontal Sobel operator')
72
+ .epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-operation#convolve')
73
+ .check(argv => {
74
+ const length = argv.width * argv.height
75
+ if (!(Array.isArray(argv.kernel) && argv.kernel.length === length)) {
76
+ throw new Error(`Expected kernel positional to have ${length} values`)
77
+ }
78
+ return true
79
+ })
80
+ .options(options)
81
+ .positional('kernel', positionals.kernel)
82
+ .positional('height', positionals.height)
83
+ .positional('width', positionals.width)
84
+ .group(optionNames, 'Command Options')
85
+ }
86
+
87
+ // Command handler.
88
+ const handler = (args) => {
89
+ return queue.push(['convolve', (sharp) => {
90
+ return sharp.convolve({
91
+ ...pick(args, positionalNames),
92
+ ...pick(args, optionNames)
93
+ })
94
+ }])
95
+ }
96
+
97
+ // Exports.
98
+ module.exports = {
99
+ command: 'convolve <width> <height> <kernel..>',
100
+ describe: 'Convolve the image with the specified kernel',
101
+ builder,
102
+ handler
103
+ }
@@ -0,0 +1,63 @@
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-operation#flatten
25
+
26
+ // Strict mode.
27
+ 'use strict'
28
+
29
+ // Local modules.
30
+ const queue = require('../../lib/queue')
31
+
32
+ // Configure.
33
+ const positionals = {
34
+ background: {
35
+ defaultDescription: 'rgb(0, 0, 0)',
36
+ desc: 'Background colour, parsed by the color module',
37
+ type: 'string'
38
+ }
39
+ }
40
+
41
+ // Command builder.
42
+ const builder = (yargs) => {
43
+ return yargs
44
+ .strict()
45
+ .example('$0 flatten "#F0A703"')
46
+ .epilog('For more information on available options, please visit https://sharp.dimens.io/api-operation#flatten')
47
+ .positional('background', positionals.background)
48
+ }
49
+
50
+ // Command handler.
51
+ const handler = (args) => {
52
+ return queue.push(['flatten', (sharp) => {
53
+ return sharp.flatten({ background: args.background })
54
+ }])
55
+ }
56
+
57
+ // Exports.
58
+ module.exports = {
59
+ command: 'flatten [background]',
60
+ describe: 'Merge alpha transparency channel, if any, with a background',
61
+ builder,
62
+ handler
63
+ }
@@ -0,0 +1,49 @@
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-operation#flip
25
+
26
+ // Strict mode.
27
+ 'use strict'
28
+
29
+ // Local modules.
30
+ const queue = require('../../lib/queue')
31
+
32
+ // Command builder.
33
+ const builder = (yargs) => {
34
+ return yargs
35
+ .strict()
36
+ .epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-operation#flip')
37
+ .example('$0 flip')
38
+ }
39
+
40
+ // Command handler.
41
+ const handler = (args) => queue.push(['flip', (sharp) => sharp.flip()])
42
+
43
+ // Exports.
44
+ module.exports = {
45
+ command: 'flip',
46
+ describe: 'Flip the image about the vertical Y axis',
47
+ builder,
48
+ handler
49
+ }
@@ -0,0 +1,49 @@
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-operation#flop
25
+
26
+ // Strict mode.
27
+ 'use strict'
28
+
29
+ // Local modules.
30
+ const queue = require('../../lib/queue')
31
+
32
+ // Command builder.
33
+ const builder = (yargs) => {
34
+ return yargs
35
+ .strict()
36
+ .epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-operation#flop')
37
+ .example('$0 flop')
38
+ }
39
+
40
+ // Command handler.
41
+ const handler = (args) => queue.push(['flop', (sharp) => sharp.flop()])
42
+
43
+ // Exports.
44
+ module.exports = {
45
+ command: 'flop',
46
+ describe: 'Flop the image about the horizontal X axis',
47
+ builder,
48
+ handler
49
+ }
@@ -0,0 +1,66 @@
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-operation#gamma
25
+
26
+ // Strict mode.
27
+ 'use strict'
28
+
29
+ // Local modules.
30
+ const queue = require('../../lib/queue')
31
+
32
+ // Configure.
33
+ const positionals = {
34
+ gamma: {
35
+ desc: 'The gamma factor',
36
+ defaultDescription: 2.2,
37
+ type: 'number'
38
+ },
39
+ gammaOut: {
40
+ desc: 'The gamma factor used for scaling',
41
+ defaultDescription: '<gamma>',
42
+ type: 'number'
43
+ }
44
+ }
45
+
46
+ // Command builder.
47
+ const builder = (yargs) => {
48
+ return yargs
49
+ .strict()
50
+ .epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-operation#gamma')
51
+ .positional('gamma', positionals.gamma)
52
+ .positional('gammaOut', positionals.gammaOut)
53
+ }
54
+
55
+ // Command handler.
56
+ const handler = (args) => queue.push(['gamma', (sharp) => {
57
+ return sharp.gamma(args.gamma, args.gammaOut)
58
+ }])
59
+
60
+ // Exports.
61
+ module.exports = {
62
+ command: 'gamma [gamma] [gammaOut]',
63
+ describe: 'Apply a gamma correction by reducing the encoding (darken) pre-resize then increasing the encoding (brighten) post-resize',
64
+ builder,
65
+ handler
66
+ }
@@ -0,0 +1,73 @@
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-operation#linear
25
+
26
+ // Strict mode.
27
+ 'use strict'
28
+
29
+ // Local modules.
30
+ const queue = require('../../lib/queue')
31
+
32
+ // Configure.
33
+ const positionals = {
34
+ multiplier: {
35
+ desc: 'Multiplier',
36
+ default: 1.0,
37
+ type: 'number'
38
+ }
39
+ }
40
+
41
+ const options = {
42
+ offset: {
43
+ desc: 'Offset',
44
+ type: 'array'
45
+ }
46
+ }
47
+
48
+ // Command builder.
49
+ const builder = (yargs) => {
50
+ const optionNames = Object.keys(options)
51
+ return yargs
52
+ .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)
57
+ .options(options)
58
+ .group(optionNames, 'Command Options')
59
+ }
60
+
61
+ // Command handler.
62
+ 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
+ }
66
+
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',
71
+ builder,
72
+ handler
73
+ }