-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (46 loc) · 1.33 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
50
51
52
53
54
import { QRCodeCanvas } from "@loskir/styled-qr-code-node";
import { existsSync, mkdirSync, readFileSync } from "fs";
const filePath = process.argv[2] || "./example.urls";
const urlsStr = readFileSync(filePath, "utf8");
if (!urlsStr) {
throw new Error(`Could not find file at path: ${filePath}`);
}
const urls = urlsStr.split("\n");
if (!urls.length) {
throw new Error(
`File at path: ${filePath} does not contain a list of new line separated connection details`
);
}
if (!existsSync("./qrs")) {
mkdirSync("./qrs");
}
urls.forEach((url, index) => {
const qrCode = new QRCodeCanvas({
width: 400,
height: 400,
data: url,
imageOptions: {
hideBackgroundDots: false,
imageSize: 0.25,
margin: 0,
},
dotsOptions: {
type: "dots",
color: "#6a1a4c",
gradient: {
type: "radial",
rotation: 0.017453292519943295,
colorStops: [
{ offset: 0, color: "#8236f3" },
{ offset: 1, color: "#3b0390" },
],
},
},
backgroundOptions: { color: "#ffffff" },
cornersSquareOptions: { type: "extra-rounded", color: "#6305f0" },
cornersDotOptions: { type: "dot", color: "#000000" },
image: "./icons/512x512.png",
});
qrCode.style = "border-radius: 16px;";
qrCode.toFile(`./qrs/${index}.png`, "png", { density: 3, quality: 1 });
});