-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsvg-converter.js
executable file
·33 lines (29 loc) · 1.02 KB
/
svg-converter.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
import fg from "fast-glob";
import fs from "node:fs";
import { parse } from "node-html-parser";
const pattern = "./selenite/semag/*/cover.svg";
const files = await fg(pattern);
for (let i = 0; i < files.length; i++) {
try {
const data = fs.readFileSync(files[i], "utf8");
const html = parse(data);
console.log(html.querySelector("image"));
fs.writeFileSync(files[i].slice(0, -9) + "cover.png", Buffer.from(html.querySelector("image").getAttribute("href").split(",")[1], "base64"));
} catch (e) {
console.log("Error: ", e);
console.log(files[i]);
}
}
const pattern2 = "./selenite/sppa/*/cover.svg";
const files2 = await fg(pattern2);
for (let i = 0; i < files2.length; i++) {
try {
const data = fs.readFileSync(files2[i], "utf8");
const html = parse(data);
console.log(html.querySelector("image"));
fs.writeFileSync(files2[i].slice(0, -9) + "cover.png", Buffer.from(html.querySelector("image").getAttribute("href").split(",")[1], "base64"));
} catch (e) {
console.log("Error: ", e);
console.log(files2[i]);
}
}