I'm using AWS lambda with python and ffmpeg to add textual watermark over images. I added a custom font i.e Quicksand to my lambda function like this:
1- Create a fonts directory in the root of the function and add the font file (.ttf) and a font.conf file with the following contents:
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<dir>/var/task/fonts/</dir>
<cachedir>/tmp/fonts-cache/</cachedir>
<config></config>
</fontconfig>
2- Added an environment variable like this
FONTCONFIG_PATH = "/var/task/fonts"
It was working fine until I chose to add more fonts. Now when I try to use some font other than the Quicksand e.g Arial, it still uses the Quicksand font. I'm not sure why? In the CloudWatch Logs I can see it is still trying to access the Quicksand font rather than the Arial one even when the code is right. Any caching issue or something else?
My Folder Structure:
My docker file:
COPY requirements.txt ./
RUN yum update -y && \
pip install -r requirements.txt
COPY . .
CMD ["app.handler"]
Cloudwatch logs:
[Parsed_drawtext_0 @ 0x70b5bc0] Using "/var/task/fonts/Quicksand.ttf"
Maybe its a caching issue? I'm not sure.
Which fonts.config file? I only have fonts.conf file and I've added that in the question. Also, the code is fine. I've added the logs and have also tried to use hardcoded font names. But it still uses the Quicksand (added first). If I remove Quicksand font then it uses the second one. But still doesn't let me use any other.
I meant the font.conf file, sorry. I am not familiar with ffmpeg, What I am saying is that it is most probably not related to Lambda, but to the library itself. I did a quick search and found the following answer, which I think can help you as well.
Thank you. I ended up storing the fonts on s3 bucket and copying them to /tmp storage for usage inside the function. Nothing else was working