Intervention/image · error · Intervention\Image\Exceptions\ImageDecoderException
Failed to decode image data from file "
Error message
Failed to decode image data from file "
What it means
Imagick::readImage($path) threw an ImagickException while loading the file. The catch block discards the original exception (no $e captured), so corrupt data, unsupported formats and policy denials all collapse into this single message. readableFilePathOrFail() already verified the file exists and is readable, so the problem is the content or the ImageMagick configuration, not filesystem permissions.
Source
Thrown at src/Drivers/Imagick/Decoders/FilePathImageDecoder.php:55
*
* @throws InvalidArgumentException
* @throws DirectoryNotFoundException
* @throws FileNotFoundException
* @throws FileNotReadableException
* @throws DriverException
* @throws StateException
* @throws ImageDecoderException
*/
public function decode(mixed $input): ImageInterface
{
// make sure path is valid
$path = self::readableFilePathOrFail($input);
try {
$imagick = new Imagick();
$imagick->readImage($path);
} catch (ImagickException) {
throw new ImageDecoderException(
'Failed to decode image data from file "' . $path . '"',
);
}
try {
$originalFormat = $imagick->getImageFormat();
} catch (ImagickException $e) {
throw new ImageDecoderException('Failed to retrieve image format', previous: $e);
}
// decode image
$image = parent::decode($imagick);
// set file path on origin
$image->origin()->setFilePath($path);
// extract exif data for the appropriate formats
if (in_array($originalFormat, ['JPEG', 'TIFF', 'TIF'])) {View on GitHub (pinned to 5598b9e397)
Solutions
- Verify the real content: run `file path` / `identify path` on the shell, or use finfo_file(), to confirm it is an actual image and see the reported format
- If the format is right but reading fails, check delegate availability: in_array('WEBP', Imagick::queryFormats()) and install the missing delegate library
- Check /etc/ImageMagick-6/policy.xml (or -7) for <policy> entries disabling the coder, path rights, or the HTTPS coder; adjust or ask the sysadmin
- For remote URLs, download with a real HTTP client first and pass the binary string or a local path instead
- Regenerate or re-save the corrupt file at its source
Example fix
// before
$image = $manager->read('https://example.com/photo.jpg'); // URL treated as path, HTTPS coder blocked by policy.xml
// after
$binary = file_get_contents('https://example.com/photo.jpg');
if ($binary === false || !str_starts_with((string) finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $binary), 'image/')) {
throw new RuntimeException('Download did not yield an image');
}
$image = $manager->read($binary); Defensive patterns
Strategy: validation
Validate before calling
$mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path);
if (!str_starts_with((string) $mime, 'image/')) {
throw new RuntimeException('Not an image file: ' . $mime);
} Try / catch
try {
$image = $manager->read($path);
} catch (\Intervention\Image\Exceptions\ImageDecoderException $e) {
// original imagick error is discarded by the library - diagnose the file externally
$logger->warning('Undecodable file: ' . $path);
throw $e;
} Prevention
- Sniff file signatures (finfo_file) instead of trusting extensions on uploads
- Download remote URLs with an HTTP client and read the bytes, not the URL-as-path
- Verify queryFormats() includes your accepted formats in every environment (dev, CI, prod)
When it happens
Trigger: ImageManager::read('path/to/file') where the bytes are not a decodable image (wrong extension, HTML/JSON error body saved as .jpg, zero-byte upload), the format needs a delegate the installed ImageMagick lacks, or ImageMagick's policy.xml disables the required coder. A remote URL passed as a string is also treated as a path and commonly fails via the HTTPS coder policy.
Common situations: Reading user uploads that failed mid-transfer; files saved from failed HTTP requests containing an error page; Debian/Ubuntu default policy.xml blocking HTTPS/PDF/PS coders; minimal Docker images without libwebp/libheif; ImageMagick 6 vs 7 format differences.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- contains unsupported image type
- 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/401867865ed66409.
Report an issue: GitHub.