问题描述
我正在尝试使用 Firebase Cloud Functions 和 ImageMagick,类似于 thumbnail demo 的完成方式。通过重新利用演示脚本,我想为 ImageMagick to split PDF pages to images 执行 CLI 命令。
convert -密度 150 演示文稿.pdf -质量 90 输出-%3d.jpg
片段
exports.splitpdfpages = functions.storage.object().onFinalize(async (object) => {
const fileBucket = object.bucket; // The Storage bucket that contains the file.
const filePath = object.name; // File path in the bucket.
const contentType = object.contentType; // File content type.
const Metageneration = object.Metageneration; // Number of times Metadata has been generated. New objects have a value of 1.
// Download file from bucket.
const bucket = admin.storage().bucket(fileBucket);
const tempFilePath = path.join(os.tmpdir(),fileName);
const tempSplitimagesPath = tempFilePath.replace(".png","_%3d.png");
await bucket.file(filePath).download({destination: tempFilePath});
console.log('PDF downloaded locally to',tempFilePath);
// Generate split page images using ImageMagick.
await spawn('convert',['-density','150',tempFilePath,'-quality','90',tempSplitimagesPath]);
console.log('pages split images created at',tempFilePath);
...
// Uploading the split images.
...
// Once the thumbnail has been uploaded delete the local file to free up disk space.
return fs.unlinkSync(tempFilePath);
});
很遗憾,我在 Cloud Functions 日志中遇到错误,指示语句错误
ChildProcessError:convert -density 150 /tmp/7eCxdDKqCb0rlYVw3AYf__foobar.pdf -quality 100 /tmp/7eCxdDKqCb0rlYVw3AYf__foobar_%3d.png
失败,代码为 1
我搜索了 resolution to the error,但它仅表明空格是问题的主要原因(根据我的陈述,没有任何空格)。调用 generateThumbnail 函数正常工作,所以我假设它基于我的更改
我是否缺少正确调用 ImageMagick 命令以将 PDF 页面转换为图像的内容?
期待收到您的来信。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)