Intervention/image · error · Intervention\Image\Exceptions\ImageDecoderException
contains unsupported image type
Error message
contains unsupported image type
What it means
Thrown by the Imagick driver when an EncodedImage object is read but its binary payload cannot be parsed. EncodedImageObjectDecoder hands the bytes to BinaryImageDecoder, which calls Imagick::readImageBlob(); when that throws a DecoderException, it is swallowed and rethrown as this ImageDecoderException. So the PHP type is fine - the bytes inside the EncodedImage are what ImageMagick cannot decode.
Source
Thrown at src/Drivers/Imagick/Decoders/EncodedImageObjectDecoder.php:47
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*
* @throws InvalidArgumentException
* @throws DriverException
* @throws StateException
* @throws ImageDecoderException
*/
public function decode(mixed $input): ImageInterface
{
if (!$input instanceof EncodedImageInterface) {
throw new InvalidArgumentException('Image source must be of type ' . EncodedImage::class);
}
try {
return parent::decode($input->toString());
} catch (DecoderException) {
throw new ImageDecoderException(EncodedImage::class . ' contains unsupported image type');
}
}
}
View on GitHub (pinned to 5598b9e397)
Solutions
- Inspect the payload before reading: check strlen() and magic bytes with finfo_buffer() or getimagesizefromstring() to confirm it is a complete, valid image
- Check delegate support in the failing environment: var_dump(Imagick::queryFormats()) and confirm the needed format (WEBP, AVIF, HEIC, SVG) is listed
- Install the missing ImageMagick delegates (libwebp, libavif, libheif, librsvg) and/or use a PHP image that bundles the imagick extension with them
- If the payload is truncated at the source, fix the producer (enlarge the blob column, store on disk, verify base64 round-trip) and re-encode
- Workaround: re-encode the source to PNG/JPEG before wrapping it in EncodedImage
Example fix
// before
$image = $manager->read($encodedImage); // payload corrupt -> ImageDecoderException
// after: verify the bytes are image data first
$binary = $encodedImage->toString();
$mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $binary);
if (!str_starts_with((string) $mime, 'image/')) {
throw new RuntimeException('EncodedImage payload is not an image, detected: ' . $mime);
}
$image = $manager->read($encodedImage); Defensive patterns
Strategy: validation
Validate before calling
$binary = $encodedImage->toString();
$mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $binary);
if ($binary === '' || !str_starts_with((string) $mime, 'image/')) {
throw new RuntimeException('EncodedImage payload is not image data');
} Type guard
function isEncodedImage(mixed $value): bool
{
return $value instanceof \Intervention\Image\Interfaces\EncodedImageInterface;
} Try / catch
try {
$image = $manager->read($encodedImage);
} catch (\Intervention\Image\Exceptions\ImageDecoderException $e) {
// payload undecodable by ImageMagick: log, re-fetch source bytes, or reject upload
$logger->error('EncodedImage undecodable: ' . $e->getMessage());
throw $e;
} Prevention
- Validate stored binary with finfo_buffer() before wrapping it in EncodedImage
- Assert Imagick::queryFormats() contains the formats your pipeline accepts, at deploy time
- Keep encoded blobs on disk or use columns large enough to avoid truncation
When it happens
Trigger: ImageManager::read() with an EncodedImage instance (e.g. one built from cached/DB-stored bytes or produced by $image->encode()) whose payload is truncated, corrupt, or in a format the installed ImageMagick has no coder/delegate for (AVIF, HEIC, WebP, SVG). An empty payload throws a different InvalidArgumentException upstream; this message specifically covers readImageBlob failure.
Common situations: Re-reading an encoded image whose bytes were truncated in a cache/DB blob column; base64 decoding that silently produced garbage; dev machine has libwebp/libheif installed but the production slim container does not; SVG passed while ImageMagick was built without RSVG; ImageMagick policy.xml disabling a coder.
Related errors
- Failed to decode image data from file "
- SplFileInfo contains unsupported image type
- Base64-encoded data contains unsupported image type
- Failed to decode unsupported image format from binary data
- Failed to retrieve image format
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/75ebb0f4e2ca48f6.
Report an issue: GitHub.