javascriptfirebasegoogle-cloud-functionsgraphicsmagick

How to handle assets like font in a Firebase function


I'm working on a Firebase function for drawing text on image. First i download locally the image from Cloud Storage and then i use graphics magick to draw text on it and finally upload this new image to Cloud Storage.

Here the Promise to draw text on image:

return new Promise((resolve, reject) => {
            gm(tempFilePath)
                .font(Roboto)
                .drawText(10, 10, "My text here")
                .write(newTempFilePath, (err, stdout) => {
                    if (err) {
                        console.error('Failed to blur image.', err);
                        reject(err);
                    } else {
                        console.log(stdout);
                        resolve(stdout);
                    }
                });
        });

The problem: How to use custom font here ?

.font(Roboto)

Is it possible to handle an asset file as a font file (Roboto-BoldItalic.ttf) in Firebase function ? Thx


Solution

  • Can you try the following:


     gm(tempFilePath)
      .font("./fonts/Roboto-BoldItalic.ttf")
      ....