Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

108
Visualizações
Canvas not rending custom font in server side image generation

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.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda