{"record":{"id":"0d6289f72e3c6a4c","repo":"Intervention/image","slug":"unsupported-media-type-mime-mediatype","errorCode":null,"errorMessage":"Unsupported media type (MIME) ${mediaType}.","messagePattern":"Unsupported media type \\(MIME\\) (.+?)\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Gd/Decoders/AbstractDecoder.php","lineNumber":44,"sourceCode":"     *\n     * @throws InvalidArgumentException\n     * @throws ImageDecoderException\n     * @throws NotSupportedException\n     * @throws DirectoryNotFoundException\n     * @throws FileNotFoundException\n     * @throws FileNotReadableException\n     */\n    protected function mediaTypeByFilePath(string $filepath): MediaType\n    {\n        $filepath = self::readableFilePathOrFail($filepath);\n\n        if (function_exists('finfo_file') && function_exists('finfo_open')) {\n            $mediaType = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $filepath);\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 . '.');\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    /**","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Gd/Decoders/AbstractDecoder.php#L26-L62","documentation":"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.","triggerScenarios":"$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.","commonSituations":"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.","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"],"exampleFix":"// before\n$image = $manager->read($request->file('avatar')->getPathname());\n\n// after\n$allowed = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];\n$mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path);\nif (!in_array($mime, $allowed, true)) {\n    throw new RuntimeException('Unsupported upload type: ' . $mime);\n}\n$image = $manager->read($path);","handlingStrategy":"validation","validationCode":"$allowed = [\n    'image/jpeg', 'image/jpg', 'image/pjpeg', 'image/x-jpeg',\n    'image/png', 'image/x-png', 'image/gif',\n    'image/webp', 'image/x-webp',\n    'image/avif', 'image/x-avif',\n    'image/bmp', 'image/x-bmp', 'image/x-ms-bmp',\n    'image/tiff', 'image/x-icon',\n];\n$mime = (string) finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path);\n$supported = in_array(strtolower($mime), $allowed, true);","typeGuard":null,"tryCatchPattern":"use Intervention\\Image\\Exceptions\\NotSupportedException;\n\ntry {\n    $image = $manager->read($path);\n} catch (NotSupportedException $e) {\n    // convert externally (rasterize SVG / transcode HEIC) or reject the upload\n    throw new RuntimeException('Please upload JPEG, PNG, GIF or WebP', 0, $e);\n}","preventionTips":["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"],"tags":["gd","decoder","mime-type","unsupported-format","finfo"],"backgroundTag":"unsupported-media-type","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}