-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (31 loc) · 933 Bytes
/
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
const fs = require('fs');
const path = require('path');
const svgexport = require('svgexport');
const inputDir = './input';
const outputDir = './output';
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir);
}
fs.readdir(inputDir, (err, files) => {
if (err) {
console.error('Error reading input directory:', err);
return;
}
files.forEach(file => {
if (path.extname(file).toLowerCase() === '.svg') {
const svgPath = path.join(inputDir, file);
const pngPath = path.join(outputDir, `${path.basename(file, '.svg')}.png`);
svgexport.render({
input: [svgPath, '100%'],
output: [pngPath, '200%:200%', 'pad'],
options: { background: 'transparent' }
}, (err) => {
if (err) {
console.error('Error converting', file, 'to PNG:', err);
} else {
console.log('Converted', file, 'to PNG:', pngPath);
}
});
}
});
});