-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·49 lines (43 loc) · 1.31 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env node
const { program } = require('commander');
const sharp = require('sharp');
const { name, version, description } = require('./package.json');
program
.name(name)
.usage(`-i <path> -o <path>`)
.addHelpText('afterAll', `\r\nExample:\r\n ${name} -i input.png -o output.png`)
.description(description)
.version(version)
.option('-i, --input <path>', 'input image file path')
.option('-o, --output <path>', 'output image file path');
program.parse();
const options = program.opts();
if (options.input && options.output) {
(async () => {
const roundedCorners = Buffer.from(
'<svg><rect x="0" y="0" width="824" height="824" rx="200" ry="200"/></svg>'
);
const input = await sharp(options.input)
.resize(824)
.composite([{
input: roundedCorners,
blend: 'dest-in'
}])
.toBuffer();
sharp({
create: {
width: 1024,
height: 1024,
channels: 4,
background: { r: 0, g: 0, b: 0, alpha: 0 }
}
})
.composite([
{ input, gravity: 'center' },
])
.png()
.toFile(options.output);
})();
} else {
program.help();
}