Change shitty lib canvas for @napi-rs/canva
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user