How to use fonts in function

I have a netlify function that creates a PNG, it works great locally, but when deployed none of the fonts work, take a look https://sfusd.netlify.app/.netlify/functions/sfusd-sign.

I see this error in the function output Fontconfig error: Cannot load default config file: No such file: (null)

I looked into what Fontconfig is and the best I found was this stackoverflow answer about how to setup fontconfig amazon web services - Include custom fonts in AWS Lambda - Stack Overflow, but as described and a few variations it still didn’t render fonts correctly and I still get the same Fontconfig error message in the function log.

Does anyone know how to setup Fontconfig for netlify functions?

I’ve got a bit more information. I added the env var FC_DEBUG=8191 which has given some more details.

It looks like setting FONTCONFIG_PATH env var doesn’t work. Here is the debug output I get.

11:09:58 AM: FC_DEBUG=8191

11:09:58 AM: Fontconfig error: Cannot load default config file: No such file: (null)

11:09:58 AM: Loading config file from memory

11:09:58 AM: Loading config file from memory done

11:09:58 AM: adding fonts from /usr/share/fonts

11:09:58 AM: cache scan dir /usr/share/fonts

11:09:58 AM: adding fonts from /.local/share/fonts

11:09:58 AM: cache scan dir /.local/share/fonts

11:09:58 AM: FontSet 0 of 0

From this output it looks like it isn’t trying to use the FONTCONFIG_PATH to load the font informaiton.

Hi @probablycorey, firstly, the reason your function worked locally is because you computer likely has fontconfig installed on it. As far as I can tell, the lambda function environment does not include fontconfig. As such, you would need to include the files needed in your function bundle. I did find an old stackoverflow answer here: https://stackoverflow.com/a/51622335 which seems to show how you could include fonts with your function, though I haven’t tested it out myself.

Hope that helps.