How to Resolve Font Rendering Issue in PNG Using Sharp and Node in Workflow?

This topic was automatically generated from Slack. You can find the original thread here.

Afternoon (in the UK at least),

I’ve been playing with a workflow that uses Node to return a Vega chart image; returning that as an SVG is fine, but when rendering that out to PNG using Sharp for easier compatability with internal systems, I hit an issue with fonts – none of the text is rendered to the image. It appears Sharp uses libsrvg for its rendering, and that relies on installed fonts – (it doesn’t support embedding the font in the SVG as base64).

Seemingly there are no fonts available for it– from some reading around my best guess is the underlying Lambda running the workflow doesn’t have any installed?

Just wondering if anyone has any ideas, has come across this as well or similar?

Hi Lee, good question - does Sharp perhaps have constructor to accept font files? Or a method to update them at runtime?

Then you could store the front in the project’s File Store and use it with Sharp

No, sadly not – it just leverages libsrvg and that expects system fonts. People directly on AWS have had success with packaging in fonts.conf and a local dir, but there’s no way (that I have found in searching) to set that within Node at runtime.

It’s only a proof-of-concept – so it’s not a deal breaker, but figured I’d ask – if we need it in production we’ll likely move to our own Lambda/Azure Function and deal with it as above.

Got it. Sorry, at this time it’s not possible, but this is a frequent ask. Whether you need binaries or assets like font files, we’re aware there are scenarios where you need custom dependencies.

We have a project in the early phase that helps address this.

Just curious, are you comfortable with writing, building and deploying Docker containers?

a little, but not very recently – I’m that most dangerous of creatures, a former engineer who is now in management… so I still like to prototype and play with tech to understand and determine if an approach is reasonable, but I make sure the real work is done by proper developers!

Hahah that’s a great description. Just curious, helps us design the features if we get a better understanding of what you’re comfortable with.

I’ll definitely forward this feedback with the team, but when we have a version of customizability for the Workflow Execution Environment that would allow something like custom fonts, we’ll definitely make an announcement at announcements