I am currently working on generating an image with node-canvas via Firebase Cloud Functions, then sending it as an email attachment with nodemailer.
The requirement of the image is that I need to input some string onto a template with a specific font.
So on Firebase Cloud Functions, here is what I did:
exports.test = functions.https.onRequest((request, response) => {
cors(request, response, () => {
let tempFilePath = path.join(os.tmpdir(), 'tnr.ttf');
functions.logger.log('tempFilePath is', tempFilePath);
bucket.file('tnr.ttf').download({destination: tempFilePath});
functions.logger.log('Font downloaded locally to', tempFilePath);
registerFont(path.resolve(tempFilePath), {family: 'tnr'});
functions.logger.log('Font registered successfully');
}
}
I have already verified repeatedly that the file 'tnr.ttf' exists on my project cloud and can successfully be loaded to that temp path.
At the registerFont function however, Firebase would always throw this error, no matter which font file I use:
Error: Could not parse font file
at registerFont (/workspace/node_modules/canvas/index.js:48:17)
Could there possibly be a problem with how Firebase handles this package or function?