首页 > 解决方案 > 仅在 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 运行时环境中执行此操作。有没有办法解决?

标签: node.jsamazon-web-servicesaws-lambdaimagemagick

解决方案


不要盲目相信文件扩展名。以非 Jpeg 格式提供的图像。您可以将其下载到另一个系统,您可以在其中使用file或其他方式进行检查。在手头的情况下,它是 WebP 图像(WebP 是 Google 推出的一种新图像格式)。

造成混淆的一个可能原因是 Web 服务器从文件扩展名生成 Mime 类型,因此 WebP 图像以 image/jpeg 的 mime 类型返回,这通常被大多数软件(包括您的浏览器)盲目信任。


推荐阅读