gpt4 book ai didi

firebase - 在 firebase 函数中使用 phantomjs

转载 作者:行者123 更新时间:2023-12-04 12:03:32 25 4
gpt4 key购买 nike

我想在 firebase 函数中使用 phantomjs 的屏幕捕获功能来返回 URL 的 PDF 屏幕截图。寻找有人这样做的例子。

最佳答案

我在 Cloud Functions 中使用了 PhantomJS,没有出现重大问题。唯一的担忧是我必须增加容器的内存,因为内存中渲染结果是内存占用。

我最终使用了 node-webshot ,它是 PhantomJS 的包装器:

"node-webshot": "^1.0.2",

捕获实际屏幕截图非常简单:
const functions = require('firebase-functions');
const webshot = require('node-webshot');

exports.screenshotTweet = functions.https.onRequest((req, res) => {
var stream = webshot(req.query.url);
res.writeHead(200, {'Content-Type': 'image/jpeg'});
stream.on('data', function(data) {
res.write(data.toString('binary'), 'binary');
});
stream.on('end', function() {
res.end();
})
});

关于firebase - 在 firebase 函数中使用 phantomjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49911661/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com