-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimgtodata.js
More file actions
26 lines (21 loc) · 758 Bytes
/
imgtodata.js
File metadata and controls
26 lines (21 loc) · 758 Bytes
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
const fs = require("fs");
const path = require("path");
try {
// Define the path to the image, assuming it's in the same directory
const imagePath = path.join(__dirname, "kmtt-background-pattern-min.png");
// Read the image file as a buffer
const imageBuffer = fs.readFileSync(imagePath);
// Convert the buffer to a base64 string
const base64Image = imageBuffer.toString("base64");
// Create the data URI
const dataUri = `data:image/png;base64,${base64Image}`;
// Output the data URI
console.log(dataUri);
} catch (error) {
console.error("Error reading file:", error.message);
if (error.code === "ENOENT") {
console.error(
"Please make sure 'clip-transparent.png' is in the same directory as this script."
);
}
}