Lee Maan
Lee Maan

Reputation: 719

Only in AWS Lambda: ImageMagick Error: Command failed: convert: no decode delegate for this image format

I have this ImageMagick error with one of the images my site is trying to convert:

{ 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 }

The weird part is that it's happening only in my AWS Lambda function, not on my machine (Mac). I am reading about versioning, reinstalling ImageMagick and stuff, but I can't do that in Lambda runtime environment. Is there any way around this?

Upvotes: 3

Views: 1487

Answers (2)

Farley
Farley

Reputation: 1488

Through some much wasted time, I figured out this is a flaw in the built-in ImageMagick that Amazon has on Lambda by default. It's older and doesn't have a decoder for WebP. If you use the following layer as an overlay for your imagemagick, and then use it instead of the built in one it will fix your problems.

https://github.com/serverlesspub/imagemagick-aws-lambda-2

Before I overlaid the above layer I was getting...

b"identify: no decode delegate for this image format `/tmp/downloaded_file' @ error/constitute.c/ReadImage/544.\n"

Afterwards...

b'/tmp/downloaded_file WEBP 740x493 740x493+0+0 8-bit sRGB 377646B 0.000u 0:00.000\n'

Most of the other answers and comments are focusing on something that is completely irrelevant, which is that the image file format is actually a webp, when imagemagick has built-in detectors for file formats and it ignores file's extension anyways, so this info is irrelevant to ImageMagick.

Enjoy anyone else that runs into this problem!!!

Upvotes: 1

xenoid
xenoid

Reputation: 8869

Don't trust file extensions blindly. The image provided in not a Jpeg. You can download it to another system where you can check it using file or else. In the case at hand it is a WebP image (WebP is a new image format pushed by Google).

One possible cause of the confusion is that Web servers generate the Mime-type from the file extension, so the WebP image is returned with a mime type of image/jpeg, and this is normally trusted blindly by most software (including your browser).

Upvotes: 2

Related Questions