Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
278 views
in Technique[技术] by (71.8m points)

javascript - 如何在Firebase函数中处理诸如字体之类的资产(How to handle assets like font in a Firebase function)

I'm working on a Firebase function for drawing text on image.

(我正在使用Firebase函数在图像上绘制文本。)

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.

(首先,我从Cloud Storage本地下载图像,然后使用graphics magick在其上绘制文本,最后将此新图像上传到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 ?

(是否可以在Firebase函数中将资产文件作为字体文件(Roboto-BoldItalic.ttf)处理?)

Thx

(谢谢)

  ask by Julien Robidet translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Can you try the following:

(您可以尝试以下方法:)


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

  • Deploy your Cloud Function(s)

    (部署您的云功能)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...