-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·125 lines (121 loc) · 2.96 KB
/
cli.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env node
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { generateImage, processList } from './imageProcessor.js';
const argv = yargs(hideBin(process.argv))
.option('amount', {
alias: 'a',
describe: 'Amount of images to generate',
type: 'number',
demandOption: false
})
.option('width', {
alias: 'w',
describe: 'Width of the images',
type: 'number',
default: 100
})
.option('height', {
alias: 'h',
describe: 'Height of the images',
type: 'number',
default: 100
})
.option('format', {
alias: 'f',
describe: 'Format of the images',
choices: ['jpg', 'png', 'webp'],
default: 'png'
})
.option('backgroundColor', {
alias: 'bg',
describe: 'Background color of the images',
type: 'string',
default: '#D3D3D3'
})
.option('textColor', {
alias: 'tc',
describe: 'Font color for text overlay',
type: 'string',
default: '#000000'
})
.option('textOverlay', {
alias: 'text',
describe: 'Text to overlay on the images',
type: 'string',
default: ''
})
.option('fontSize', {
describe: 'Font size for text overlay',
type: 'number',
default: 48
})
.option('autoFontSize', {
alias: 'auto-fs',
describe: 'Automatically adjust font size based on image dimensions',
type: 'boolean',
default: false
})
.option('output', {
alias: 'o',
describe: 'Output path for the generated images',
type: 'string',
default: process.cwd()
})
.option('list', {
describe: 'Path to a text or JSON file with a list of options for generating multiple images',
type: 'string'
})
.option('prefix', {
describe: 'Prefix for filenames when generating multiple images',
type: 'string',
default: 'image-'
})
.option('verbose', {
alias: 'v',
describe: 'Print verbose output',
type: 'boolean',
default: false
})
.option('watermarks', {
describe: 'Watermark settings',
type: 'object',
coerce: arg => {
if (typeof arg === 'string') {
return JSON.parse(arg);
}
return arg;
},
})
.check(argv => {
if (!argv.list && !argv.amount) {
throw new Error('You must provide either --amount for single image generation or --list for bulk generation.');
}
if (argv.list && argv.amount) {
throw new Error('Please provide either --list or --amount, not both.');
}
if (argv.autoFontSize && argv.fontSize) {
throw new Error('Please provide either --fontSize or --autoFontSize, not both.');
}
if (!argv.output) {
throw new Error('Output path is required.');
}
return true;
})
.argv;
const main = async () => {
if (argv.list) {
await processList(argv.list, argv);
} else {
for (let i = 0; i < argv.amount; i++) {
await generateImage({
...argv,
filename: `${argv.prefix}${i + 1}`,
});
}
}
};
main().catch(err => {
console.error(err);
process.exit(1);
});