-
Notifications
You must be signed in to change notification settings - Fork 6
/
sign.js
27 lines (21 loc) · 931 Bytes
/
sign.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
// sign.js
import Jimp from 'jimp';
import fs from 'fs/promises';
export const signQRCode = async (inputPath, outputPath, qrFilename) => {
const image = await Jimp.read(inputPath);
const font = await Jimp.loadFont(Jimp.FONT_SANS_16_BLACK); // Load a readable font
// Add a semi-transparent background to the text for better readability
const backgroundColor = 0x00000080;
const padding = 5;
// Write "qrpwd" at the top left corner within the white margin
image.print(font, padding, padding, 'qrpwd');
// Write the filename at the left bottom corner within the white margin
image.print(font, padding, image.bitmap.height - 16 - padding, qrFilename.replace('.png', ''));
// Remove the existing file before writing a new one, if it exists
try {
await fs.rm(outputPath, { force: true });
} catch (error) {
// Ignore the error if the file doesn't exist
}
await image.writeAsync(outputPath);
};