google-cloud-functions - Firebase Cloud Functions-ImageMagick CLI PDF to images
问题描述
我正在尝试使用 Firebase Cloud Functions 和 ImageMagick,类似于缩略图演示的完成方式。通过重新调整演示脚本的用途,我想为ImageMagick 执行 CLI 命令以将 PDF 页面拆分为图像。
转换-密度 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
我搜索了错误的解决方案,但它仅表明空格是问题的主要原因(根据我的陈述没有任何问题)。调用 generateThumbnail 函数可以正常工作,所以我假设它基于我的更改
我是否缺少正确调用 ImageMagick 命令以将 PDF 页面转换为图像的内容?
期待您的来信。
解决方案
推荐阅读
- docker - 将fabric8io docker-maven-plugin与podman一起使用,mvn docker:build会导致IO-Exception
- java - Android Studio 布局验证错误?
- angular - 在 Angular 中定期调用健康检查 API
- javascript - Discord.js - setNickname 没有足够的权限
- python - 在 NLP 中合并相关词
- google-sheets - 如何在整个工作表中找到具有特定值的单元格
- django - Nginx 在 Django 应用程序上使用 Gunicorn 重定向无法正常工作
- php - \Image::make 生产失败(Laravel)
- javascript - 识别 useStyles 中未使用的样式
- c++ - 为什么我的程序会跳过我的 switch 语句,直接进入默认状态?