-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·32 lines (28 loc) · 1.02 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
#!/usr/bin/env node
const program = require('commander');
const images = require('images');
const package = require('./package.json');
program.version(package.version);
/**
* 合并图片
* @param {*} options
*/
const mergeAction = options => {
const { background, flag, target } = options;
const bg_image = images(background);
const gq_image = images(flag);
const offset = { x: 5, y: 5 };
const foreground_image = images(gq_image.width() + offset.x, gq_image.height() + offset.y).fill(0xff, 0xff, 0xff, 1).draw(gq_image, offset.x, offset.y);
const pos = {
x: bg_image.width() - gq_image.width(),
y: bg_image.height() - gq_image.height(),
};
bg_image.draw(foreground_image, pos.x, pos.y).save(target, { quality: 100 });
};
program.command('merge')
.description('合并图片')
.option('-b, --background <background image>', '背景图片')
.option('-f, --flag <flag image>', '国旗图片')
.option('-t, --target <target image name>', '合成图片')
.action(mergeAction);
program.parse(process.argv);