Change shitty lib canvas for @napi-rs/canva

This commit is contained in:
2025-11-11 21:31:34 +01:00
parent 9cc2f7c169
commit e3218af147
2 changed files with 3 additions and 14 deletions

View File

@@ -21,7 +21,7 @@
"author": "Naaturel",
"license": "MIT",
"dependencies": {
"canvas": "^3.2.0",
"@napi-rs/canvas": "^0.1.82",
"discord.js": "^14.22.1",
"dotenv": "^16.0.3",
"express": "^4.21.2",

View File

@@ -1,19 +1,8 @@
import fs from "fs";
import path from "path";
import { createCanvas, loadImage, registerFont } from "canvas";
import { createCanvas, loadImage } from "@napi-rs/canvas";
export class NameCardCreator {
constructor(templatePath) {
this.templatePath = templatePath;
this.loadFont("./wwwroot/assets/fonts/Fredoka/static/Fredoka-Bold.ttf");
}
loadFont(fontPath) {
const fullPath = path.resolve(fontPath);
if (!fs.existsSync(fullPath)) {
throw new Error(`Font file not found at ${fullPath}`);
}
registerFont(fullPath, { family: "Fredoka Bold" });
}
/**
@@ -85,7 +74,7 @@ export class NameCardCreator {
smallCtx = smallCanvas.getContext("2d");
smallCtx.drawImage(canvas, 0, 0, 1500, 500);
return smallCanvas.toBuffer();
return smallCanvas.toBuffer("image/png");
} catch (err) {
console.error("Error creating name card:", err);
throw err;