Intervention/image · error · NotSupportedException
Unsupported media type (MIME) ${mime}.
Error message
Unsupported media type (MIME) ${mime}. What it means
Thrown by the GD driver when the MIME type detected for a file via finfo_file is a string, but MediaType::from() has no matching enum case. Intervention Image only accepts a fixed list of media types (jpeg, png, gif, webp, avif, bmp, tiff, jp2, heic, heif, jxl, ico variants); any other detected MIME (e.g. image/svg+xml, application/pdf, image/vnd.wap.wbmp) is rejected as unsupported before decoding starts.
Source
Thrown at src/Drivers/Gd/Decoders/AbstractDecoder.php:58
if (is_string($mediaType)) {
try {
return MediaType::from($mediaType);
} catch (ValueError | TypeError) {
throw new NotSupportedException('Unsupported media type (MIME) ' . $mediaType . '.');
}
}
}
$info = @getimagesize($filepath);
if (!is_array($info)) {
throw new ImageDecoderException('Failed to read media (MIME) type from data in file path');
}
try {
return MediaType::from($info['mime']);
} catch (ValueError | TypeError) {
throw new NotSupportedException('Unsupported media type (MIME) ' . $info['mime'] . '.');
}
}
/**
* Return media (mime) type of the given image data
*
* @throws ImageDecoderException
* @throws NotSupportedException
*/
protected function mediaTypeByBinary(string $data): MediaType
{
if (function_exists('finfo_buffer') && function_exists('finfo_open')) {
$mediaType = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $data);
if (is_string($mediaType)) {
try {
return MediaType::from($mediaType);
} catch (ValueError | TypeError) {
throw new NotSupportedException('Unsupported media type (MIME) ' . $mediaType . '.');View on GitHub (pinned to 5598b9e397)
Solutions
- Verify what the file really is: run mime_content_type($path) or file -b on it and compare against the MediaType enum cases in src/MediaType.php
- If the input should be an image, re-export or convert it to a supported format (PNG/JPEG/WebP/GIF/BMP/AVIF) before calling read()
- If you must handle TIFF/HEIC/JP2/JXL/ICO, switch the manager to the Imagick driver (new ImageManager(new Driver(ImagickDriver::class))) or withDriver(ImagickDriver::class), since GD cannot decode them anyway
- Reject or quarantine non-image uploads at validation time (extension + finfo whitelist) instead of letting the decoder fail
Example fix
// before
$image = $manager->read('/storage/uploads/avatar.svg');
// NotSupportedException: Unsupported media type (MIME) image/svg+xml.
// after
$allowed = ['image/jpeg','image/png','image/gif','image/webp','image/avif','image/bmp'];
if (!in_array(mime_content_type('/storage/uploads/avatar.svg'), $allowed, true)) {
throw new RuntimeException('Upload is not a supported image format');
}
$image = $manager->read('/storage/uploads/avatar.svg'); Defensive patterns
Strategy: validation
Validate before calling
$mime = mime_content_type('/path/to/file');
$supported = [
'image/jpeg', 'image/png', 'image/gif', 'image/webp',
'image/avif', 'image/bmp', 'image/tiff', 'image/heic', 'image/x-icon',
];
if (!in_array($mime, $supported, true)) {
throw new RuntimeException('Unsupported media type: ' . $mime);
} Try / catch
try {
$image = $manager->read($path);
} catch (\Intervention\Image\Exceptions\NotSupportedException $e) {
// message names the offending MIME; reject input, do not retry
logger()->warning('Rejected upload', ['mime_error' => $e->getMessage()]);
} Prevention
- Whelist sniffed MIME types at the upload boundary, not just extensions
- Compare any exotic format against the MediaType enum before processing
- Route TIFF/HEIC-family inputs to the Imagick driver from the start
When it happens
Trigger: Calling ImageManager::read('/path/to/file') (or the internal mediaTypeByFilePath used by FilePathImageDecoder::decode) where the file's finfo-detected MIME is not in the MediaType enum: SVG uploads, PDFs renamed to .png, WBMP/XPM images, camera raw formats (image/x-canon-cr2), or text files whose content finfo sniffs as a non-listed type.
Common situations: User uploads an SVG avatar and the app feeds the stored path straight to read(); processing a mixed document/image inbox; files with wrong extensions but detectable non-image content; environments where fileinfo extension sniffs an unexpected MIME for an exotic format.
Related errors
- File contains unsupported image format
- Unsupported media type (MIME) ${mediaType}.
- Base64-encoded data contains unsupported image type
- Failed to decode unsupported image format from binary data
- Data Uri contains unsupported image type
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/0635d29c92cadce2.
Report an issue: GitHub.