微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Firebase Cloud Functions-ImageMagick CLI PDF 到图像

如何解决Firebase Cloud Functions-ImageMagick CLI PDF 到图像

我正在尝试使用 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 举报,一经查实,本站将立刻删除。