Skip to main content
  • Pricing
Tutorials

Base64 to Image: Decode a Data URL

By Oakgen TeamPublished 1 min read

Share
Base64 to Image: Decode a Data URL

A Base64 image string represents image bytes in text form. A data URL includes an extra header. In data:image/png;base64,..., the first comma separates the media declaration from the encoded payload.

Decode and verify

  1. Check whether your input starts with data:. If it does, parse the header and take the part after the first comma. A raw Base64 string already starts at the payload.
  2. Decode the payload into bytes. Treat a decoding error as a reason to check where the string came from. Some formats use the URL-safe Base64 alphabet, so identify the variant before changing characters.
  3. Verify that the bytes are an image of the claimed type. Give the output the appropriate filename extension after verification. A declaration of image/png does not transform JPEG or text bytes into a PNG.

Pick a safe place to decode it

For private images, decode locally. Base64 is an encoding that anyone with the text can reverse, so avoid pasting personal photos or signed document images into tools you do not control. Use a small, disposable sample while checking your processing logic.

If the image came from a web page you own, a data URL can simplify one-file examples. For heavier assets, saving a regular image file can make the page easier to maintain and keep the encoded string out of HTML.

Continue with Oakgen Agent

Coming soon: A dedicated one-click Base64 image decoder.

Open in Oakgen Agent

The prompt is filled in for you. Review it before sending.

Open in Oakgen Agent

Sources

  1. MDN, data: URLs
Share