Install a new font on AWS Lamba

前端 未结 2 1646
感动是毒
感动是毒 2021-01-28 16:47

I\'m installing Imagemagick on AWS Lambda and it appears that the fonts that Imagemagick normally uses aren\'t preinstalled, how can I add additional fonts?

相关标签:
2条回答
  • 2021-01-28 17:24

    Here's what I just got to work for custom fonts on AWS Lambda with pandoc/xelatex. I assume you can do something very similar to get Imagemagick to work correctly.

    I created a fonts directory in my project and placed all of my fonts there. Also in that directory I created a fonts.conf file that looks like this:

    <?xml version="1.0"?>
    <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
    <fontconfig>
      <dir>/var/task/fonts/</dir>
      <cachedir>/tmp/fonts-cache/</cachedir>
      <config></config>
    </fontconfig>
    

    And then in my (node.js based) handler function before shelling out to call pandoc I set an ENV var to tell fontconfig where to find the fonts.

    process.env.FONTCONFIG_PATH='/var/task/fonts'
    

    After doing that I can refer to a font, like Bitter, in my template by name (just Bitter) and then pandoc/xelatex/fontconfig/whatever knows which version of the font to use (like Bitter-Bold.otf vs Bitter-Italic.otf) based on the styling that any bit of text is supposed to have.

    I figured this out based on the tips in this project for getting RSVG to work with custom fonts on Lambda: https://github.com/claudiajs/rsvg-convert-aws-lambda-binary/blob/master/README.md#using-custom-fonts

    0 讨论(0)
  • 2021-01-28 17:27

    You can't.

    The reason you can even use Imagemagick with your lambda is because AWS Lambda team had pre-installed this library on their containers.

    This is true for Lambda's running on NodeJS - which has libraries for operating the Imagemagick installed on your OS but not running it itself.

    You should examine using C# / Java runtimes - which might have the Imagemagick library that you can add to your Lambda (not sure about that).

    0 讨论(0)
提交回复
热议问题