@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.
- package/.gitattributes +1 -0
- package/CHANGELOG.md +336 -0
- package/LICENSE.txt +20 -0
- package/README.md +35 -0
- package/bin/cli.js +32 -0
- package/changes.json +26 -0
- package/cmd/channel-manipulation/bandbool.js +61 -0
- package/cmd/channel-manipulation/ensure-alpha.js +62 -0
- package/cmd/channel-manipulation/extract-channel.js +61 -0
- package/cmd/channel-manipulation/join-channel.js +60 -0
- package/cmd/channel-manipulation/remove-alpha.js +49 -0
- package/cmd/colour-manipulation/greyscale.js +50 -0
- package/cmd/colour-manipulation/pipeline-colourspace.js +63 -0
- package/cmd/colour-manipulation/tint.js +58 -0
- package/cmd/colour-manipulation/tocolourspace.js +63 -0
- package/cmd/compositing/composite.js +187 -0
- package/cmd/operations/affine.js +110 -0
- package/cmd/operations/blur.js +87 -0
- package/cmd/operations/boolean.js +66 -0
- package/cmd/operations/clahe.js +82 -0
- package/cmd/operations/convolve.js +103 -0
- package/cmd/operations/flatten.js +63 -0
- package/cmd/operations/flip.js +49 -0
- package/cmd/operations/flop.js +49 -0
- package/cmd/operations/gamma.js +66 -0
- package/cmd/operations/linear.js +73 -0
- package/cmd/operations/median.js +62 -0
- package/cmd/operations/modulate.js +78 -0
- package/cmd/operations/negate.js +60 -0
- package/cmd/operations/normalise.js +69 -0
- package/cmd/operations/recomb.js +74 -0
- package/cmd/operations/rotate.js +72 -0
- package/cmd/operations/sharpen.js +109 -0
- package/cmd/operations/threshold.js +73 -0
- package/cmd/operations/unflatten.js +49 -0
- package/cmd/output.js +125 -0
- package/cmd/resizing/extend.js +102 -0
- package/cmd/resizing/extract.js +79 -0
- package/cmd/resizing/resize.js +124 -0
- package/cmd/resizing/trim.js +82 -0
- package/lib/cli.js +800 -0
- package/lib/constants.js +55 -0
- package/lib/convert.js +121 -0
- package/lib/index.js +58 -0
- package/lib/queue.js +44 -0
- package/package.json +84 -0
|
@@ -0,0 +1,60 @@
|
|
|
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-channel#joinchannel
|
|
25
|
+
|
|
26
|
+
// Strict mode.
|
|
27
|
+
'use strict'
|
|
28
|
+
|
|
29
|
+
// Local modules.
|
|
30
|
+
const queue = require('../../lib/queue')
|
|
31
|
+
|
|
32
|
+
// Configure.
|
|
33
|
+
const positionals = {
|
|
34
|
+
images: {
|
|
35
|
+
desc: 'One or more images',
|
|
36
|
+
normalize: true,
|
|
37
|
+
type: 'array'
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Command builder.
|
|
42
|
+
const builder = (yargs) => {
|
|
43
|
+
return yargs
|
|
44
|
+
.strict()
|
|
45
|
+
.epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-channel#joinchannel')
|
|
46
|
+
.positional('images', positionals.images)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Command handler.
|
|
50
|
+
const handler = (args) => {
|
|
51
|
+
return queue.push(['joinChannel', (sharp) => sharp.joinChannel(args.images)])
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Exports.
|
|
55
|
+
module.exports = {
|
|
56
|
+
command: 'joinChannel <images..>',
|
|
57
|
+
describe: 'Join one or more channels to the image',
|
|
58
|
+
builder,
|
|
59
|
+
handler
|
|
60
|
+
}
|
|
@@ -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-channel#removealpha
|
|
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
|
+
.example('$0 removeAlpha', 'The output will be without an alpha channel')
|
|
37
|
+
.epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-channel#removealpha')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Command handler.
|
|
41
|
+
const handler = (args) => queue.push(['removeAlpha', (sharp) => sharp.removeAlpha()])
|
|
42
|
+
|
|
43
|
+
// Exports.
|
|
44
|
+
module.exports = {
|
|
45
|
+
command: 'removeAlpha',
|
|
46
|
+
describe: 'Remove alpha channel, if any',
|
|
47
|
+
builder,
|
|
48
|
+
handler
|
|
49
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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-colour#greyscale
|
|
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
|
+
.example('$0 greyscale', 'The output will contain three identical color channels')
|
|
37
|
+
.epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-colour#greyscale')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Command handler.
|
|
41
|
+
const handler = (args) => queue.push(['greyscale', (sharp) => sharp.greyscale()])
|
|
42
|
+
|
|
43
|
+
// Exports.
|
|
44
|
+
module.exports = {
|
|
45
|
+
command: 'greyscale',
|
|
46
|
+
aliases: 'grayscale',
|
|
47
|
+
describe: 'Convert to 8-bit greyscale; 256 shades of grey',
|
|
48
|
+
builder,
|
|
49
|
+
handler
|
|
50
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
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-colour#tocolourspace
|
|
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
|
+
colourspace: {
|
|
36
|
+
alias: 'colorspace',
|
|
37
|
+
choices: constants.COLOURSPACE,
|
|
38
|
+
desc: 'Pipeline colourspace'
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Command builder.
|
|
43
|
+
const builder = (yargs) => {
|
|
44
|
+
return yargs
|
|
45
|
+
.strict()
|
|
46
|
+
.example('$0 pipelineColourspace rgb16', 'Run the pipeline in 16 bits per channel RGB')
|
|
47
|
+
.epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-colour#tocolourspace')
|
|
48
|
+
.positional('colourspacae', positionals.colourspace)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Command handler.
|
|
52
|
+
const handler = (args) => {
|
|
53
|
+
return queue.push(['pipelineColourspace', (sharp) => sharp.pipelineColourspace(args.colourspace)])
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Exports.
|
|
57
|
+
module.exports = {
|
|
58
|
+
command: 'pipelineColourspace <colourspace>',
|
|
59
|
+
aliases: 'pipelineColorspace',
|
|
60
|
+
describe: 'Set the pipeline colourspace',
|
|
61
|
+
builder,
|
|
62
|
+
handler
|
|
63
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
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-colour#tint
|
|
25
|
+
|
|
26
|
+
// Strict mode.
|
|
27
|
+
'use strict'
|
|
28
|
+
|
|
29
|
+
// Local modules.
|
|
30
|
+
const queue = require('../../lib/queue')
|
|
31
|
+
|
|
32
|
+
// Configure.
|
|
33
|
+
const positionals = {
|
|
34
|
+
rgb: {
|
|
35
|
+
desc: 'Parsed by the color module to extract chroma values',
|
|
36
|
+
type: 'string'
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Command builder.
|
|
41
|
+
const builder = (yargs) => {
|
|
42
|
+
return yargs
|
|
43
|
+
.strict()
|
|
44
|
+
.example('$0 tint "rgb(255, 240, 16)"')
|
|
45
|
+
.epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-colour#tint')
|
|
46
|
+
.positional('rgb', positionals.rgb)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Command handler.
|
|
50
|
+
const handler = (args) => queue.push(['tint', (sharp) => sharp.tint(args.rgb)])
|
|
51
|
+
|
|
52
|
+
// Exports.
|
|
53
|
+
module.exports = {
|
|
54
|
+
command: 'tint <rgb>',
|
|
55
|
+
describe: 'Tint the image using the provided chroma while preserving the image luminance',
|
|
56
|
+
builder,
|
|
57
|
+
handler
|
|
58
|
+
}
|
|
@@ -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.pixelplumbing.com/api-colour#tocolourspace
|
|
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
|
+
colourspace: {
|
|
36
|
+
choices: constants.COLOURSPACE,
|
|
37
|
+
default: 'srgb',
|
|
38
|
+
desc: 'The output colourspace'
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Command builder.
|
|
43
|
+
const builder = (yargs) => {
|
|
44
|
+
return yargs
|
|
45
|
+
.strict()
|
|
46
|
+
.example('$0 toColourspace rgb16', 'Output 16 bits per pixel RGB')
|
|
47
|
+
.epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-colour#tocolourspace')
|
|
48
|
+
.positional('colourspace', positionals.colourspace)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Command handler.
|
|
52
|
+
const handler = (args) => {
|
|
53
|
+
return queue.push(['toColourspace', (sharp) => sharp.toColourspace(args.colourspace)])
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Exports.
|
|
57
|
+
module.exports = {
|
|
58
|
+
command: 'toColourspace <colourspace>',
|
|
59
|
+
aliases: 'toColorspace',
|
|
60
|
+
describe: 'Set the output colourspace',
|
|
61
|
+
builder,
|
|
62
|
+
handler
|
|
63
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
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 http://sharp.pixelplumbing.com/api-composite#composite
|
|
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
|
+
// Helpers.
|
|
34
|
+
function getValueAt (arrayLike, index) {
|
|
35
|
+
if (Array.isArray(arrayLike)) {
|
|
36
|
+
return arrayLike[Math.min(index, arrayLike.length - 1)]
|
|
37
|
+
}
|
|
38
|
+
return arrayLike
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function hasOwnProperty (obj, prop) {
|
|
42
|
+
return obj != null && Object.prototype.hasOwnProperty.call(obj, prop)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Configure.
|
|
46
|
+
const positionals = {
|
|
47
|
+
images: {
|
|
48
|
+
desc: 'Path to an image file',
|
|
49
|
+
normalize: true,
|
|
50
|
+
type: 'string'
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const options = {
|
|
55
|
+
blend: {
|
|
56
|
+
choices: constants.BLEND,
|
|
57
|
+
defaultDescription: 'over',
|
|
58
|
+
desc: 'How to blend this image with the image below'
|
|
59
|
+
},
|
|
60
|
+
create: {
|
|
61
|
+
desc: 'Describes a blank overlay to be created',
|
|
62
|
+
hidden: true,
|
|
63
|
+
type: 'boolean'
|
|
64
|
+
},
|
|
65
|
+
'create.background': {
|
|
66
|
+
desc: 'Background of the blank overlay to be created, parsed by the color module',
|
|
67
|
+
type: 'string'
|
|
68
|
+
},
|
|
69
|
+
'create.channels': {
|
|
70
|
+
choices: [3, 4],
|
|
71
|
+
default: 3,
|
|
72
|
+
desc: 'Number of channels of the blank overlay to be created'
|
|
73
|
+
},
|
|
74
|
+
'create.height': {
|
|
75
|
+
desc: 'Height of the blank overlay to be created',
|
|
76
|
+
type: 'number'
|
|
77
|
+
},
|
|
78
|
+
'create.width': {
|
|
79
|
+
desc: 'Width of the blank overlay to be created',
|
|
80
|
+
type: 'number'
|
|
81
|
+
},
|
|
82
|
+
density: {
|
|
83
|
+
desc: 'Number representing the DPI for vector images',
|
|
84
|
+
defaultDescription: 72,
|
|
85
|
+
type: 'number'
|
|
86
|
+
},
|
|
87
|
+
gravity: {
|
|
88
|
+
choices: constants.GRAVITY,
|
|
89
|
+
defaultDescription: 'centre',
|
|
90
|
+
desc: 'Gravity at which to place the overlay'
|
|
91
|
+
},
|
|
92
|
+
left: {
|
|
93
|
+
desc: 'The pixel offset from the left edge',
|
|
94
|
+
implies: 'top',
|
|
95
|
+
type: 'number'
|
|
96
|
+
},
|
|
97
|
+
premultiplied: {
|
|
98
|
+
desc: 'Avoid premultiplying the image',
|
|
99
|
+
type: 'boolean'
|
|
100
|
+
},
|
|
101
|
+
tile: {
|
|
102
|
+
desc: 'Repeat the overlay image across the entire image with the given gravity',
|
|
103
|
+
type: 'boolean'
|
|
104
|
+
},
|
|
105
|
+
top: {
|
|
106
|
+
desc: 'The pixel offset from the top edge',
|
|
107
|
+
implies: 'left',
|
|
108
|
+
type: 'number'
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Command builder.
|
|
113
|
+
const builder = (yargs) => {
|
|
114
|
+
const optionNames = Object.keys(options)
|
|
115
|
+
return yargs
|
|
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')
|
|
125
|
+
}
|
|
126
|
+
return true
|
|
127
|
+
})
|
|
128
|
+
.options(options)
|
|
129
|
+
.group(optionNames, 'Command Options')
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Command handler.
|
|
133
|
+
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')
|
|
137
|
+
}
|
|
138
|
+
|
|
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 })
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (args.images) inputs.push(...args.images)
|
|
157
|
+
|
|
158
|
+
// @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
|
+
}
|
|
180
|
+
|
|
181
|
+
// Exports.
|
|
182
|
+
module.exports = {
|
|
183
|
+
command: 'composite [images..]',
|
|
184
|
+
describe: 'Composite image(s) over the processed (resized, extracted etc.) image',
|
|
185
|
+
builder,
|
|
186
|
+
handler
|
|
187
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
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#affine
|
|
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 placeholders = {
|
|
38
|
+
matrix: {
|
|
39
|
+
desc: 'Affine transformation matrix',
|
|
40
|
+
nargs: 2 * 2,
|
|
41
|
+
type: 'number'
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const options = {
|
|
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'
|
|
50
|
+
},
|
|
51
|
+
idx: {
|
|
52
|
+
defaultDescription: '0',
|
|
53
|
+
desc: 'The input horizontal offset',
|
|
54
|
+
type: 'number'
|
|
55
|
+
},
|
|
56
|
+
idy: {
|
|
57
|
+
defaultDescription: '0',
|
|
58
|
+
desc: 'The input vertical offset',
|
|
59
|
+
type: 'number'
|
|
60
|
+
},
|
|
61
|
+
odx: {
|
|
62
|
+
defaultDescription: '0',
|
|
63
|
+
desc: 'The output horizontal offset',
|
|
64
|
+
type: 'number'
|
|
65
|
+
},
|
|
66
|
+
ody: {
|
|
67
|
+
defaultDescription: '0',
|
|
68
|
+
desc: 'The output vertical offset',
|
|
69
|
+
type: 'number'
|
|
70
|
+
},
|
|
71
|
+
interpolate: {
|
|
72
|
+
choices: constants.INTERPOLATORS,
|
|
73
|
+
defaultDescription: 'bicubic',
|
|
74
|
+
desc: 'The input horizontal offset'
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const optionNames = Object.keys(options)
|
|
78
|
+
|
|
79
|
+
// Command builder.
|
|
80
|
+
const builder = (yargs) => {
|
|
81
|
+
return yargs
|
|
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 => {
|
|
86
|
+
if (!(Array.isArray(argv.matrix) && argv.matrix.length === 4)) {
|
|
87
|
+
throw new Error('Expected matrix positional to have 4 values')
|
|
88
|
+
}
|
|
89
|
+
return true
|
|
90
|
+
})
|
|
91
|
+
.positional('matrix', placeholders.matrix)
|
|
92
|
+
.options(options)
|
|
93
|
+
.group(optionNames, 'Command Options')
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Command handler.
|
|
97
|
+
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
|
+
}
|
|
103
|
+
|
|
104
|
+
// Exports.
|
|
105
|
+
module.exports = {
|
|
106
|
+
command: 'affine <matrix..>',
|
|
107
|
+
describe: 'Perform an affine transform on an image',
|
|
108
|
+
builder,
|
|
109
|
+
handler
|
|
110
|
+
}
|