node.js - 仅在 AWS Lambda 中:ImageMagick 错误:命令失败:转换:没有此图像格式的解码委托
问题描述
我的网站尝试转换的其中一张图像出现此 ImageMagick 错误:
{ Error: Command failed: convert: no decode delegate for this image format `/tmp/925bf249f8297827f51f0370642eb560.jpg' @ error/constitute.c/ReadImage/544.
convert: no images defined `/tmp/abdf362d-f7eb-435f-bafe-5a134be0235f.png' @ error/convert.c/ConvertImageCommand/3046.
at ChildProcess.<anonymous> (/var/task/node_modules/imagemagick/imagemagick.js:88:15)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:886:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5) timedOut: false, killed: false, code: 1, signal: null }
奇怪的是它只发生在我的 AWS Lambda 函数中,而不是我的机器(Mac)上。我正在阅读有关版本控制、重新安装 ImageMagick 之类的内容,但我无法在 Lambda 运行时环境中执行此操作。有没有办法解决?
解决方案
不要盲目相信文件扩展名。以非 Jpeg 格式提供的图像。您可以将其下载到另一个系统,您可以在其中使用file
或其他方式进行检查。在手头的情况下,它是 WebP 图像(WebP 是 Google 推出的一种新图像格式)。
造成混淆的一个可能原因是 Web 服务器从文件扩展名生成 Mime 类型,因此 WebP 图像以 image/jpeg 的 mime 类型返回,这通常被大多数软件(包括您的浏览器)盲目信任。
推荐阅读
- python-3.x - PyGTK3:从键盘捕获字符串
- c# - Azure 函数 - 此平台不支持 System.Data.SqlClient
- ios - 如何以编程方式设置 UIRefreshControl 微调器大小?
- django - 使用 UserPassesTestMixin(基于类的视图)和重定向
- google-sheets - Google表格中不同工作簿的联合范围
- c++ - 范围运算符需要找到 std 命名空间而不是 boost
- android - 从头开始制作自定义 ROM 需要什么?
- ruby-on-rails - 使用从另一个站点抓取的内容填充 Rails 应用程序
- c# - Azure 移动应用同步服务推送无法插入或更新
- python - 发布数据应该是字节。它不能是 str 类型