{"record":{"id":"2232bc6b1ac6d957","repo":"Intervention/image","slug":"base64-encoded-data-contains-unsupported-image-typ-2232bc","errorCode":null,"errorMessage":"Base64-encoded data contains unsupported image type","messagePattern":"Base64-encoded data contains unsupported image type","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\ImageDecoderException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Decoders/Base64ImageDecoder.php","lineNumber":42,"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":24,"sourceCodeEnd":46,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Decoders/Base64ImageDecoder.php#L24-L46","documentation":"Thrown by Base64ImageDecoder when the string decoded from base64 successfully, but the parent BinaryImageDecoder could not turn the resulting bytes into an image (its DecoderException is remapped to this message). So the base64 was fine; the payload is not a format Imagick can read.","triggerScenarios":"$manager->read($base64) where the decoded bytes are: a truncated image file (cut-off upload), plain text or JSON that happened to look base64-ish, an image format the local ImageMagick build lacks delegates for (AVIF, WebP, SVG without rsvg, HEIC), or a zero-signature blob.","commonSituations":"Client uploads truncated by size limits; receiving base64-of-base64; environments where imagick was compiled without webp/heif delegates so previously working images now fail; error pages or HTML bodies encoded where an image was expected.","solutions":["Decode and inspect the first bytes: valid images start with known signatures (\\x89PNG, \\xFF\\xD8 JPEG, GIF8)","Re-export/re-upload the source file to rule out truncation","Check ImageMagick delegate support: convert -list format | grep -i webp (and install delegates)","Catch ImageDecoderException at the read() call and reject the upload with a user-facing message"],"exampleFix":"// before: trusting any base64 from the client\n$image = $manager->read($request->input('image'));\n\n// after: verify decoded bytes look like an image first\n$bytes = base64_decode(preg_replace('/\\s+/', '', $input), true);\n$ok = $bytes !== false && (str_starts_with($bytes, \"\\x89PNG\") || str_starts_with($bytes, \"\\xFF\\xD8\") || str_starts_with($bytes, 'GIF8'));\n$image = $ok ? $manager->read($input) : throw new InvalidArgumentException('not an image');","handlingStrategy":"try-catch","validationCode":"$bytes = base64_decode(preg_replace('/\\s+/', '', $input), true);\nif ($bytes === false || strlen($bytes) < 8) {\n    throw new InvalidArgumentException('base64 payload too short to be an image');\n}\n$sig = substr($bytes, 0, 4);\n$known = [\"\\x89PNG\", \"\\xFF\\xD8\\xFF\", 'GIF8', 'RIFF'];\nif (!in_array(substr($sig, 0, 3), array_map(fn ($k) => substr($k, 0, 3), $known), true)) {\n    throw new InvalidArgumentException('decoded data has no known image signature');\n}","typeGuard":null,"tryCatchPattern":"use Intervention\\Image\\Exceptions\\ImageDecoderException;\n\ntry {\n    $image = $manager->read($base64);\n} catch (ImageDecoderException $e) {\n    report($e);\n    return response()->json(['error' => 'unsupported-image-format'], 422);\n}","preventionTips":["Sniff magic bytes of the decoded payload before handing it to the decoder","Check delegate coverage (convert -list format) whenever a new format enters your product","Reject uploads where the decoded size is implausibly small"],"tags":["base64","unsupported-format","decoding","imagick"],"backgroundTag":"unsupported-image-format","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}