How to convert Base64 into an image format?

Learn how to convert Base64 to JPG, PNG, or other image formats using an online tool or JavaScript, with solutions to common conversion problems.

Have you received a Base64 string that you need to convert into a JPG, PNG, or another image format? Base64 is a method for representing binary data as text; therefore, you must decode it before you can view or save the image.

Below are a few simple ways to convert Base64 data into an image.

What is a Base64 image?

A Base64 image is image data encoded into a text format. It typically appears as a long string consisting of letters, numbers, and symbols.

Some Base64 image strings begin with a "data URL" prefix, for example:

`data:image/png;base64,`

This prefix identifies the image format and instructs the browser on how to parse the data.

How to convert Base64 to an image online

Using an online Base64-to-image tool is one of the easiest methods.

1. Copy the complete Base64 string.
2. Open a Base64-to-image tool.
3. Paste the string into the input field.
4. Click the "Convert" or "Decode" button.
5. Preview the image and download it in your desired format.

If the tool supports local processing, your image data will be decoded directly within your browser, without needing to be uploaded to a server.

How to convert Base64 to an image using JavaScript

You can also decode Base64 image data with JavaScript.

const base64 = "YOUR_BASE64_STRING";

const img = document.createElement("img");
img.src = base64.startsWith("data:image/")
  ? base64
  : "data:image/png;base64," + base64;

document.body.appendChild(img);

If you need to save the image, you can create a download link:

const link = document.createElement("a");
link.href = img.src;
link.download = "image.png";
link.click();

Replace YOUR_BASE64_STRING with your actual Base64 data.

The image fails to display. Check whether the Base64-encoded string is complete and if the correct image format is specified.
The decoded image appears corrupted. The string might contain extra spaces, missing characters, or an incorrect prefix.

The image format is unknown. A Base64 string does not always explicitly indicate its original file format. Before saving, check the Data URL prefix or examine the content of the decoded file.

Once the text is decoded into image data, the process of converting Base64 to an image is quite straightforward. Online conversion tools are useful for quick tasks, while in web applications, you can use JavaScript to display or download Base64-encoded images.

Ensure that you select the correct image format and that the Base64 string is complete to avoid conversion errors.


Convert an image now

The converter reads PNG, JPG, GIF, BMP, TIFF, ICO, WebP, AVIF, HEIC and SVG, and writes PNG, JPG, WebP, GIF, BMP, TIFF, ICO, AVIF and PDF. It states for each file whether the work happened on your device or on the server.

More guides