How to turn Base64 into an image
- Paste the Base64 into the box. You may include the
data:image/...;base64,prefix or leave it out. - The image appears below, with its type, size and pixel dimensions.
- Press Download file to save it with the right extension.
The file type is detected from the first bytes of the data, not from the prefix, so a wrong or missing prefix does not matter. A PDF is detected as well, and can be downloaded.
Recognise the type from the first characters
Every file format starts with a fixed byte pattern, which gives the Base64 a typical beginning:
| Base64 starts with | File type |
|---|---|
iVBORw0KGgo | PNG image |
/9j/ | JPEG image |
R0lGOD | GIF image |
UklGR | WebP image (RIFF container) |
PHN2Zy or PD94bW | SVG image (text starting with <svg or <?xml) |
Qk | BMP image |
AAABAA | ICO icon |
JVBERi0 | PDF document |
If the image does not show
- The text is cut. A truncated string decodes to a damaged image. Copy the complete value; long strings are often shortened in logs and consoles.
- Extra characters. Quotes,
url(and)from CSS, or a JSON key should not be part of the input. Tick Ignore invalid characters to skip stray characters. - Plus signs became spaces. This happens when the value passed through a URL or a form. Replace spaces with
+. - It is not an image. The tool still decodes it and tells you what it found, for instance a ZIP file or text.
- Double encoding. If the decoded data itself is Base64 text, decode it once more with the Base64 decoder.
Show a Base64 image in HTML
<img src="data:image/png;base64,iVBORw0KGgo..." alt="">
Save a Base64 image in code
// Node.js
require('fs').writeFileSync('out.png', Buffer.from(b64, 'base64'));
// PHP
file_put_contents('out.png', base64_decode($b64));
# Python
open('out.png', 'wb').write(base64.b64decode(b64))
# Shell
base64 --decode input.txt > out.png
Privacy and safety
Decoding runs in your browser, and nothing is uploaded. SVG is shown through an image element, where scripts inside the file do not run. Still, download and open files only if you trust where the data came from.
To encode a picture, use image to Base64. See also the Base64 decoder and What is Base64?