Intervention/image · error · ImageDecoderException
Base64-encoded data contains unsupported image type
Error message
Base64-encoded data contains unsupported image type
What it means
Thrown by Base64ImageDecoder::decode when the Base64 decoding itself succeeded, but passing the resulting binary to BinaryImageDecoder::decode raised a DecoderException. The decoded payload is therefore not an image the GD driver can process — it is another file type, an unsupported image format, or corrupted image data.
Source
Thrown at src/Drivers/Gd/Decoders/Base64ImageDecoder.php:43
}
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*/
public function decode(mixed $input): ImageInterface
{
try {
$data = $this->decodeBase64Data($input);
} catch (DecoderException) {
throw new ImageDecoderException('Unable to Base64-decode image from string');
}
try {
return parent::decode($data);
} catch (DecoderException) {
throw new ImageDecoderException('Base64-encoded data contains unsupported image type');
}
}
}
View on GitHub (pinned to 5598b9e397)
Solutions
- Decode and inspect the payload manually: $bin = base64_decode($s, true); var_dump(strlen($bin), substr($bin, 0, 16), @getimagesizefromstring($bin));
- Verify the column/transport length (TEXT not VARCHAR(255)) and re-test with a fresh, known-good upload
- Convert the source to PNG/JPEG client-side or in a pre-processing step if it is HEIC/TIFF/SVG
- Wrap read() in try/catch on ImageDecoderException and return a validation error to the uploader
Example fix
// before
$image = $manager->read($request->input('image'));
// ImageDecoderException: Base64-encoded data contains unsupported image type
// after
$bin = base64_decode(preg_replace('/\s+/', '', $request->input('image')), true);
if ($bin === false || @getimagesizefromstring($bin) === false) {
return back()->withErrors(['image' => 'Please upload a PNG, JPEG, GIF or WebP image.']);
}
$image = $manager->read(base64_encode($bin)); Defensive patterns
Strategy: try-catch
Validate before calling
$bin = base64_decode(preg_replace('/\s+/', '', $b64), true);
if ($bin === false || $bin === '' || @getimagesizefromstring($bin) === false) {
throw new RuntimeException('Base64 payload is not a decodable image');
} Try / catch
try {
$image = $manager->read($b64);
} catch (\Intervention\Image\Exceptions\ImageDecoderException $e) {
// payload decoded but content is unsupported/corrupt; return validation error
return response()->json(['error' => 'Unsupported image data'], 422);
} Prevention
- Use TEXT/MEDIUMTEXT columns so base64 payloads are never truncated
- Cap and validate upload size before base64 round-trips
- Convert HEIC/SVG client-side to PNG/JPEG before base64-encoding
When it happens
Trigger: ImageManager::read($base64String) where the payload decodes to a PDF/SVG/TIFF/HEIC, to a truncated PNG/JPEG (clipped upload), to an empty result, or to an image in a format this GD build cannot parse. The parent BinaryImageDecoder throws (empty string, imagecreatefromstring === false, or unmapped MIME) and it is re-wrapped as this ImageDecoderException.
Common situations: Base64 round-trips through JSON or databases that silently truncate long values (VARCHAR too short, cut multipart bodies); clients base64-encoding whatever file the user picked; HEIC photos from iPhones on servers without AVIF/HEIC handling; double-encoded payloads (base64 of base64).
Related errors
- Failed to decode unsupported image format from binary data
- Unsupported media type (MIME) ${mime}.
- File contains unsupported image format
- Failed to read media (MIME) type from binary data
- Unable to Base64-decode image from string
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/e07d66842ecc35b1.
Report an issue: GitHub.