{"record":{"id":"0635d29c92cadce2","repo":"Intervention/image","slug":"unsupported-media-type-mime-mime","errorCode":null,"errorMessage":"Unsupported media type (MIME) ${mime}.","messagePattern":"Unsupported media type \\(MIME\\) (.+?)\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Gd/Decoders/AbstractDecoder.php","lineNumber":58,"sourceCode":"            if (is_string($mediaType)) {\n                try {\n                    return MediaType::from($mediaType);\n                } catch (ValueError | TypeError) {\n                    throw new NotSupportedException('Unsupported media type (MIME) ' . $mediaType . '.');\n                }\n            }\n        }\n\n        $info = @getimagesize($filepath);\n\n        if (!is_array($info)) {\n            throw new ImageDecoderException('Failed to read media (MIME) type from data in file path');\n        }\n\n        try {\n            return MediaType::from($info['mime']);\n        } catch (ValueError | TypeError) {\n            throw new NotSupportedException('Unsupported media type (MIME) ' . $info['mime'] . '.');\n        }\n    }\n\n    /**\n     * Return media (mime) type of the given image data\n     *\n     * @throws ImageDecoderException\n     * @throws NotSupportedException\n     */\n    protected function mediaTypeByBinary(string $data): MediaType\n    {\n        if (function_exists('finfo_buffer') && function_exists('finfo_open')) {\n            $mediaType = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $data);\n            if (is_string($mediaType)) {\n                try {\n                    return MediaType::from($mediaType);\n                } catch (ValueError | TypeError) {\n                    throw new NotSupportedException('Unsupported media type (MIME) ' . $mediaType . '.');","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Gd/Decoders/AbstractDecoder.php#L40-L76","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n$image = $manager->read('/storage/uploads/avatar.svg');\n// NotSupportedException: Unsupported media type (MIME) image/svg+xml.\n\n// after\n$allowed = ['image/jpeg','image/png','image/gif','image/webp','image/avif','image/bmp'];\nif (!in_array(mime_content_type('/storage/uploads/avatar.svg'), $allowed, true)) {\n    throw new RuntimeException('Upload is not a supported image format');\n}\n$image = $manager->read('/storage/uploads/avatar.svg');","handlingStrategy":"validation","validationCode":"$mime = mime_content_type('/path/to/file');\n$supported = [\n    'image/jpeg', 'image/png', 'image/gif', 'image/webp',\n    'image/avif', 'image/bmp', 'image/tiff', 'image/heic', 'image/x-icon',\n];\nif (!in_array($mime, $supported, true)) {\n    throw new RuntimeException('Unsupported media type: ' . $mime);\n}","typeGuard":null,"tryCatchPattern":"try {\n    $image = $manager->read($path);\n} catch (\\Intervention\\Image\\Exceptions\\NotSupportedException $e) {\n    // message names the offending MIME; reject input, do not retry\n    logger()->warning('Rejected upload', ['mime_error' => $e->getMessage()]);\n}","preventionTips":["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"],"tags":["mime-type","finfo","gd-driver","decoder","unsupported-format","file-upload"],"backgroundTag":"unsupported-media-type","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}