Ask coding questions

← Back to all posts
Cannot add text to Node.js canvas
tamkerl (9)

I'm trying to make a captcha system, and right now experimenting with creating a canvas with text on it.
However, when I try to do that, the image file is created, but the text is not visible, and the console shows "Fontconfig error: Cannot load default config file".

I tried searching for it, and I found an answer here: https://askubuntu.com/questions/492033/fontconfig-error-cannot-load-default-config-file.
But that answer involved editing a file that is not accessible from Repl.it.
Does anyone know how to fix this in any other way?
Thanks.

Comments
hotnewtop
chandlerpc (0)

I have the same error, i'm working on a discord bot

chandlerpc (0)

Hey, I solved the problem, the error is because repl.it don have files .ttf, you only download a .tff and upload to repl.it proyect, on the code you need to change the direction of your file for the new typography, now the console know the typography, sorry for my bad english.
@PROSmash

GlitchyBrick (2)

@chandlerpc Hey, I added the .ttf file to my project how do i change the direction of the file

this is my code
ctx.font = '35px sans-serif'

chandlerpc (0)

@GlitchyBrick you can use the
registerFont function,like this

registerFont('./Impact.ttf', { family: 'Impact' });

In the canvas this :
ctx.font = '28px Impact';