#Canvas custom font not registering

47 messages · Page 1 of 1 (latest)

stoic escarp
#

Hello i use node-canvas in my discord bot but when register font locally it works but when its deployed it don't, any tips why?

registerFont(`${__dirname}/../../fonts/Poppins-Bold.ttf`, {
  family: "Poppins",
  style: "bold",
});

It just make the text with the default font

smoky plumeBOT
#

Project ID: 628e9bd7-1359-4b90-aa85-0c48855bd942

stoic escarp
#
    ctx.fillStyle = "white";
    ctx.textAlign = "center";
    ctx.font = "bold 18px Poppins";
    ctx.fillText(shape.memberName, circleX, rectY + 80);

    ctx.fillStyle = "#4e4e6a";
    ctx.textAlign = "center";
    ctx.font = "semi 12px Poppins";
    ctx.fillText(shape.memberUsername, circleX, rectY + 95);

    ctx.fillStyle = "#676786";
    ctx.textAlign = "center";
    ctx.font = "semi 14px Poppins";
    ctx.fillText(
      Math.floor(shape.voiceTimeMs / 60000) + " minutes",
      circleX,
      canvasHeight - 20
    );```
proven meadow
#

it's likely that your path is just incorrect
@exotic goblet do you see what could be causing the font to not get loaded?

exotic goblet
#

Unfortunately, I’m not too familiar with node-canvas

#

I’d have to play with it and see what’s going on

proven meadow
#

but is that a proper path? looks like it could be simplified?

exotic goblet
#

The way it’s being called there feels like it would be treated as a system font, instead of an imported one

#

If it can’t find it, it will default to actual system fonts

proven meadow
#

@stoic escarp - are you providing this font in your repo?

exotic goblet
#

This doesn’t look promising

#

No docs

proven meadow
exotic goblet
#

They said node-canvas not canvas

proven meadow
#

maybe the path is correct, but the container is missing the lib that would read the font file?

#

npm names are confusing

#

this would still count as node-canvas

exotic goblet
#

This is why I don’t use node

proven meadow
#

fair

#

register font doesn't return an error 🙄

exotic goblet
#

But according to the canvas docs, the implementation is correct

proven meadow
#

correct, though probably sub optimal import path

exotic goblet
#

Might be time to throw some console.log() statements. Unless someone familiar with the package knows what’s going on

proven meadow
#

no one is familiar with npm packages

exotic goblet
#

Fair

proven meadow
#

im working on a test, will get back to you!

stoic escarp
stoic escarp
stoic escarp
proven meadow
#

he uses perl

stoic escarp
#

oh

proven meadow
#

sometimes even assembly if he feels like it

proven meadow
#

im not even joking

exotic goblet
#

He’s really not joking. Perl, python, PHP, go, c#, you name it

proven meadow
#

and thats only a tiny fraction of the languages

stoic escarp
stoic escarp
# proven meadow <@397137454215200789> - https://test-service2.up.railway.app/

The register was no err but while generating image i got ```(process:22020): Pango-WARNING **: 20:36:57.742: couldn't load font "Poppins Bold Not-Rotated 28px", falling back to "Sans Bold Not-Rotated 28px", expect ugly output.

(process:22020): Pango-WARNING **: 20:36:58.349: couldn't load font "Poppins Bold Not-Rotated 18px", falling back to "Sans Bold Not-Rotated 18px", expect ugly output.

(process:22020): Pango-WARNING **: 20:36:58.354: couldn't load font "Poppins Bold Not-Rotated 12px", falling back to "Sans Bold Not-Rotated 12px", expect ugly output.

(process:22020): Pango-WARNING **: 20:36:58.363: couldn't load font "Poppins Bold Not-Rotated 14px", falling back to "Sans Bold Not-Rotated 14px", expect ugly output.```

proven meadow
#

yeah I got that on windows too, but works fine on railway as you can see by my demo site

stoic escarp
#

i will try it, wait

lavish lavaBOT