Intervention/image · error · NotSupportedException
Unsupported media type (MIME) ${mediaType}.
Error message
Unsupported media type (MIME) ${mediaType}. What it means
When reading from a file path, the GD decoders detect the media type with finfo_file() and map it through the MediaType enum (src/MediaType.php:13-44). If the detected MIME string is not one of the supported cases (jpeg, webp, gif, png, avif, bmp, tiff, jp2/jpx/jpm, heic/heif, jxl, ico variants), MediaType::from() throws ValueError and it is rethrown as this NotSupportedException. Note this fires even for types the enum knows but GD itself cannot decode — decoding support is checked later by the decoder chain.
Source
Thrown at src/Drivers/Gd/Decoders/AbstractDecoder.php:44
*
* @throws InvalidArgumentException
* @throws ImageDecoderException
* @throws NotSupportedException
* @throws DirectoryNotFoundException
* @throws FileNotFoundException
* @throws FileNotReadableException
*/
protected function mediaTypeByFilePath(string $filepath): MediaType
{
$filepath = self::readableFilePathOrFail($filepath);
if (function_exists('finfo_file') && function_exists('finfo_open')) {
$mediaType = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $filepath);
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'] . '.');
}
}
/**View on GitHub (pinned to 5598b9e397)
Solutions
- Whitelist uploads before read(): check finfo_file() or getimagesize() mime against your supported set (image/jpeg, image/png, image/gif, image/webp under GD)
- Convert unsupported sources externally (rasterize SVG with librsvg/resvg, transcode HEIC) before handing them to Intervention Image
- Switch to the Imagick driver for broader format coverage where the extension is available
- If the MIME looks valid but unusual, re-save the file with a conformant encoder so finfo reports a standard type
Example fix
// before
$image = $manager->read($request->file('avatar')->getPathname());
// after
$allowed = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
$mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path);
if (!in_array($mime, $allowed, true)) {
throw new RuntimeException('Unsupported upload type: ' . $mime);
}
$image = $manager->read($path); Defensive patterns
Strategy: validation
Validate before calling
$allowed = [
'image/jpeg', 'image/jpg', 'image/pjpeg', 'image/x-jpeg',
'image/png', 'image/x-png', 'image/gif',
'image/webp', 'image/x-webp',
'image/avif', 'image/x-avif',
'image/bmp', 'image/x-bmp', 'image/x-ms-bmp',
'image/tiff', 'image/x-icon',
];
$mime = (string) finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path);
$supported = in_array(strtolower($mime), $allowed, true); Try / catch
use Intervention\Image\Exceptions\NotSupportedException;
try {
$image = $manager->read($path);
} catch (NotSupportedException $e) {
// convert externally (rasterize SVG / transcode HEIC) or reject the upload
throw new RuntimeException('Please upload JPEG, PNG, GIF or WebP', 0, $e);
} Prevention
- Whitelist upload MIME types before calling read()
- Reject SVG for GD-driven raster processing; rasterize it upstream if needed
- Keep the format whitelist in one config shared by validation and image code
When it happens
Trigger: $manager->read('drawing.svg') (image/svg+xml is not in the enum); reading PDFs, videos, or text files; exotic MIME spellings like image/heic-sequence or application/octet-stream returned by a misconfigured finfo magic database.
Common situations: Accepting user uploads without MIME whitelisting (HTML error pages saved as .jpg); SVG logos fed to a raster library; server finfo returning vendor-specific MIME variants; HEIC iPhone photos on stacks without HEIC decoding.
Related errors
- Unsupported media type (MIME) ${mime}.
- Failed to read media (MIME) type from data in file path
- File contains unsupported image format
- Unknown color format
- Base64-encoded data contains unsupported image type
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/0d6289f72e3c6a4c.
Report an issue: GitHub.