I am trying to use Canvas to generate images via an API because I need to programmatically generate images using a background image and overlaying custom text.
I am writing the server in Node JS.
Current implementation in "pages/api/image.js":
import "@fontsource/press-start-2p"; //Font I am trying to use -- successfully loads in React web UI
const { createCanvas, loadImage } = require("canvas");
export async function generateImage(body) {
const canvas = createCanvas(width, height);
const context = canvas.getContext("2d");
...
context.drawImage(image, 0, 0, width, height); //draws background image - no problem
...
context.font = "16pt Press Start 2P"; //Font defaults to other alternative
context.fillText("Sample text", 40, 40);
I cannot figure out if Canvas cannot support the custom font, or if I am loading the font incorrectly.
Does anyone have any tips on how to generate these images with the custom font? I am open to a non Canvas solution if that is a limitation of the package.