How to register font in canvas discord.js v13


This Content is from Stack Overflow. Question asked by Bohdan

I ran into a problem when I try to register a font, canvas gives me a warning and does not display the font right away, but only the second time. How can this problem be solved?

const canvas = Canvas.createCanvas(1920, 1080)
    const context = canvas.getContext('2d');

    registerFont('./Xeniacondensed.ttf', { family: 'Xenia'})

    const background = await Canvas.loadImage('./pho.jpg')

    context.drawImage(background, 0, 0, canvas.width, canvas.height)

    context.font = '100pt "Xenia"';

    context.fillStyle = '#0664b9';

    context.fillText(message.guild.memberCount, canvas.width / 5, canvas.height / 1.85)

    message.reply({ files: [
             attachment: canvas.toBuffer()
    ] });


(process:2244): Pango-WARNING **: 11:24:26.851: couldn't load font "XeniaCondensed Not-Rotated 133.3330078125px", falling back to "Sans Not-Rotated 133.3330078125px", expect ugly output.  


Check the Answers

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?