Home / Developer tools / Base64 to image

Base64 to Image Converter

Paste a Base64 string or a data URI and see the picture. The tool detects the file type from the data itself, shows its size and dimensions, and lets you download it.

Try:

Everything runs in your browser. Your data is not sent to our server.

How to turn Base64 into an image

  1. Paste the Base64 into the box. You may include the data:image/...;base64, prefix or leave it out.
  2. The image appears below, with its type, size and pixel dimensions.
  3. 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 withFile type
iVBORw0KGgoPNG image
/9j/JPEG image
R0lGODGIF image
UklGRWebP image (RIFF container)
PHN2Zy or PD94bWSVG image (text starting with <svg or <?xml)
QkBMP image
AAABAAICO icon
JVBERi0PDF 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?

Frequently asked questions

How do I convert Base64 to an image?

Paste the Base64 or data URI. The image is shown at once. Press Download file to save it.

Do I need the data:image prefix?

No. The type is detected from the data. If a prefix is present it is removed.

Why is my Base64 image broken?

Most often the string is cut short, contains extra characters, or had + replaced by spaces. Check the full length and remove quotes or CSS around it.

Can I convert Base64 to PDF?

Yes. A PDF is detected from its header (JVBERi0), and you can download it with the .pdf extension.