{"record":{"id":"169a5760fa03220d","repo":"Intervention/image","slug":"data-uri-contains-unsupported-image-type","errorCode":null,"errorMessage":"Data Uri contains unsupported image type","messagePattern":"Data Uri contains unsupported image type","errorType":"exception","errorClass":"ImageDecoderException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Gd/Decoders/DataUriImageDecoder.php","lineNumber":49,"sourceCode":"\n    /**\n     * {@inheritdoc}\n     *\n     * @see DecoderInterface::decode()\n     *\n     * @throws InvalidArgumentException\n     * @throws DriverException\n     * @throws ImageDecoderException\n     * @throws StateException\n     * @throws NotSupportedException\n     */\n    public function decode(mixed $input): ImageInterface\n    {\n        if ($input instanceof DataUri) {\n            try {\n                return parent::decode($input->data());\n            } catch (DecoderException) {\n                throw new ImageDecoderException('Data Uri contains unsupported image type');\n            }\n        }\n\n        if (!is_string($input)) {\n            throw new InvalidArgumentException(\n                'Image source must be data uri scheme of type string or ' . DataUri::class,\n            );\n        }\n\n        try {\n            return parent::decode(DataUri::parse($input)->data());\n        } catch (DecoderException) {\n            throw new ImageDecoderException('Data Uri contains unsupported image type');\n        }\n    }\n}\n","sourceCodeStart":31,"sourceCodeEnd":66,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Gd/Decoders/DataUriImageDecoder.php#L31-L66","documentation":"DataUriImageDecoder::decode was given a DataUri object; its embedded binary was handed to the binary decoder chain, which threw a DecoderException. The data URI itself parsed fine — the bytes inside it are not an image the GD driver can decode, so the failure is re-thrown as this ImageDecoderException.","triggerScenarios":"ImageManager::read($dataUriObject) (or a direct decoder call) where DataUri->data() yields SVG text, PDF bytes, a truncated image, or a TIFF/HEIC payload. The inner BinaryImageDecoder::decode throws (format failure, empty data, or unmapped MIME) and is wrapped with this message.","commonSituations":"Rich-text editors (TinyMCE, CKEditor paste-as-image) embedding image data URIs that occasionally carry SVG; DataUri::parse used on unvalidated user strings; payloads that went through HTML encoding and came back with damaged bytes; pipelines storing DataUri objects in session/cache between requests.","solutions":["Inspect the payload: $dataUri->data() then getimagesizefromstring / magic bytes to identify the real content","Reject or rasterize non-raster payloads (SVG -> PNG via rsvg/ImageMagick) before creating the DataUri","Validate at input time when the data URI is a string: decode the base64 part and confirm it is a GD-supported image","Catch ImageDecoderException around read() and surface a meaningful upload error instead of a 500"],"exampleFix":"// before\n$uri = DataUri::parse($request->input('inline_image'));\n$image = $manager->read($uri);\n// ImageDecoderException: Data Uri contains unsupported image type\n\n// after\n$uri = DataUri::parse($request->input('inline_image'));\nif (@getimagesizefromstring($uri->data()) === false) {\n    throw new InvalidArgumentException('Inline image must be PNG, JPEG, GIF or WebP.');\n}\n$image = $manager->read($uri);","handlingStrategy":"try-catch","validationCode":"if ($dataUri instanceof \\Intervention\\Image\\DataUri && @getimagesizefromstring($dataUri->data()) === false) {\n    throw new RuntimeException('Data URI does not contain a decodable raster image');\n}","typeGuard":"function containsDecodableImage(\\Intervention\\Image\\Interfaces\\DataUriInterface $uri): bool\n{\n    return @getimagesizefromstring($uri->data()) !== false;\n}","tryCatchPattern":"try {\n    $image = $manager->read($dataUri);\n} catch (\\Intervention\\Image\\Exceptions\\ImageDecoderException $e) {\n    // embedded bytes are not GD-decodable; reject or rasterize first\n}","preventionTips":["Validate editor-pasted data URIs (they often carry SVG) before storing them","Decode the base64 section and sniff the format at input time","Keep DataUri payloads small and length-checked"],"tags":["data-uri","unsupported-format","decoder","gd-driver","wysiwyg"],"backgroundTag":"unsupported-image-format","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}