{"record":{"id":"e07d66842ecc35b1","repo":"Intervention/image","slug":"base64-encoded-data-contains-unsupported-image-typ","errorCode":null,"errorMessage":"Base64-encoded data contains unsupported image type","messagePattern":"Base64-encoded data contains unsupported image type","errorType":"exception","errorClass":"ImageDecoderException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Gd/Decoders/Base64ImageDecoder.php","lineNumber":43,"sourceCode":"    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see DecoderInterface::decode()\n     */\n    public function decode(mixed $input): ImageInterface\n    {\n        try {\n            $data = $this->decodeBase64Data($input);\n        } catch (DecoderException) {\n            throw new ImageDecoderException('Unable to Base64-decode image from string');\n        }\n\n        try {\n            return parent::decode($data);\n        } catch (DecoderException) {\n            throw new ImageDecoderException('Base64-encoded data contains unsupported image type');\n        }\n    }\n}\n","sourceCodeStart":25,"sourceCodeEnd":47,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Gd/Decoders/Base64ImageDecoder.php#L25-L47","documentation":"Thrown by Base64ImageDecoder::decode when the Base64 decoding itself succeeded, but passing the resulting binary to BinaryImageDecoder::decode raised a DecoderException. The decoded payload is therefore not an image the GD driver can process — it is another file type, an unsupported image format, or corrupted image data.","triggerScenarios":"ImageManager::read($base64String) where the payload decodes to a PDF/SVG/TIFF/HEIC, to a truncated PNG/JPEG (clipped upload), to an empty result, or to an image in a format this GD build cannot parse. The parent BinaryImageDecoder throws (empty string, imagecreatefromstring === false, or unmapped MIME) and it is re-wrapped as this ImageDecoderException.","commonSituations":"Base64 round-trips through JSON or databases that silently truncate long values (VARCHAR too short, cut multipart bodies); clients base64-encoding whatever file the user picked; HEIC photos from iPhones on servers without AVIF/HEIC handling; double-encoded payloads (base64 of base64).","solutions":["Decode and inspect the payload manually: $bin = base64_decode($s, true); var_dump(strlen($bin), substr($bin, 0, 16), @getimagesizefromstring($bin));","Verify the column/transport length (TEXT not VARCHAR(255)) and re-test with a fresh, known-good upload","Convert the source to PNG/JPEG client-side or in a pre-processing step if it is HEIC/TIFF/SVG","Wrap read() in try/catch on ImageDecoderException and return a validation error to the uploader"],"exampleFix":"// before\n$image = $manager->read($request->input('image'));\n// ImageDecoderException: Base64-encoded data contains unsupported image type\n\n// after\n$bin = base64_decode(preg_replace('/\\s+/', '', $request->input('image')), true);\nif ($bin === false || @getimagesizefromstring($bin) === false) {\n    return back()->withErrors(['image' => 'Please upload a PNG, JPEG, GIF or WebP image.']);\n}\n$image = $manager->read(base64_encode($bin));","handlingStrategy":"try-catch","validationCode":"$bin = base64_decode(preg_replace('/\\s+/', '', $b64), true);\nif ($bin === false || $bin === '' || @getimagesizefromstring($bin) === false) {\n    throw new RuntimeException('Base64 payload is not a decodable image');\n}","typeGuard":null,"tryCatchPattern":"try {\n    $image = $manager->read($b64);\n} catch (\\Intervention\\Image\\Exceptions\\ImageDecoderException $e) {\n    // payload decoded but content is unsupported/corrupt; return validation error\n    return response()->json(['error' => 'Unsupported image data'], 422);\n}","preventionTips":["Use TEXT/MEDIUMTEXT columns so base64 payloads are never truncated","Cap and validate upload size before base64 round-trips","Convert HEIC/SVG client-side to PNG/JPEG before base64-encoding"],"tags":["base64","unsupported-format","corrupt-file","decoder","gd-driver","file-upload"],"backgroundTag":"unsupported-image-format","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}