Change shitty lib canvas for @napi-rs/canva
This commit is contained in:
@@ -21,7 +21,7 @@
|
|||||||
"author": "Naaturel",
|
"author": "Naaturel",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"canvas": "^3.2.0",
|
"@napi-rs/canvas": "^0.1.82",
|
||||||
"discord.js": "^14.22.1",
|
"discord.js": "^14.22.1",
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
"express": "^4.21.2",
|
"express": "^4.21.2",
|
||||||
|
|||||||
@@ -1,19 +1,8 @@
|
|||||||
import fs from "fs";
|
import { createCanvas, loadImage } from "@napi-rs/canvas";
|
||||||
import path from "path";
|
|
||||||
import { createCanvas, loadImage, registerFont } from "canvas";
|
|
||||||
|
|
||||||
export class NameCardCreator {
|
export class NameCardCreator {
|
||||||
constructor(templatePath) {
|
constructor(templatePath) {
|
||||||
this.templatePath = 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 = smallCanvas.getContext("2d");
|
||||||
smallCtx.drawImage(canvas, 0, 0, 1500, 500);
|
smallCtx.drawImage(canvas, 0, 0, 1500, 500);
|
||||||
|
|
||||||
return smallCanvas.toBuffer();
|
return smallCanvas.toBuffer("image/png");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Error creating name card:", err);
|
console.error("Error creating name card:", err);
|
||||||
throw err;
|
throw err;
|
||||||
|
|||||||
Reference in New Issue
Block a user