Text Problem when converting SVG to PNG on AWS Lambda
See original GitHub issueWhat is the output of running npx envinfo --binaries --languages --system --utilities?
My code is running on AWS Lambda Node 10, so I can not invoke this command.
What are the steps to reproduce? On AWS Lambda I run the following function :
...
exports.handler = async function(event) {
const result = await sharp("/tmp/ImageTemplateBis.svg").png().toBuffer();
return {
statusCode: 200,
headers: {
'Content-Type': 'image/png'
},
body: result.toString('base64'),
isBase64Encoded: true
}
It works. The following image is returned. But the text rendering fails (I get rectangles instead of letters)

What is the expected behaviour?
Running this code locally (on Mac) and storing it to a file results in the following png with pretty letters :

I attached the svg in case this helps.
ImageTemplateBis.svg.zip
Thank you!
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (3 by maintainers)
Top Results From Across the Web
AWS lambda convert svg to png - node.js - Stack Overflow
I would like to use the AWS Lambda service to convert SVG to PNG with the language NodeJS. In a second time, the...
Read more >[Solved]-AWS lambda convert svg to png-node.js
Coding example for the question AWS lambda convert svg to png-node.js. ... based on the styling that any bit of text is supposed...
Read more >Convert SVG to PNG on Meteor - help
From my experience working with SVGs converting them to PNG, doesn't maintain quality of the image, you will probably end up with fuzzy...
Read more >Content type conversions in API Gateway - AWS Documentation
When converting a text payload to a binary blob, API Gateway assumes that the text data is a base64-encoded string and outputs the...
Read more >convert-svg-to-png - npm
Converts SVG to PNG using headless Chromium. Latest version: 0.6.4, last published: 7 months ago. Start using convert-svg-to-png in your ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

THANKS! Figured it out! Going to add my input here on how I got this to work incase anyone else is having trouble rendering fonts in AWS Lambda like this ticket describes. Also thanks to @lovell for being super responsive to all of the tickets and keeping up with the project.
Since the aws lambda environment doesn’t seem like it has fonts, you have to download them, package them up with your project and reference the path to them (so sharp can get to them) with the
FONTCONFIG_PATHenv set to where the fonts will be.So need to create a fonts.conf file that has this XML in it, in the same folder where you store the fonts. I stored mine in a folder called
fontsThen in your function set the font path to this:
process.env.FONTCONFIG_PATH='/var/task/fonts'the
var/task/path is where your lambda function lives on the aws lambda container. So you just need to create a folder in you project calledfontsand put this fonts.conf file in it along with a font file. And boom, you’ve got fonts with your shiney new PNG image.Note: that the font file has to be a
.ttffont file type like Roboto-Regular.ttf from google fonts.@MattGohr First of all THANK YOU!!!
Second, its
fonts.confnotfont.conf. Can you please update your post. Thanks.