How to Convert an Image to Base64
Enter non-empty base64-encoded image data, select the desired data-URI setting, and run the conversion. Success provides base64 output, with a MIME-tagged data URI included when that option is enabled.
Purpose and input
Image to Base64 works with supplied base64-encoded image data. It decodes the text and attempts to open the resulting bytes as an image before producing a base64 representation of the original image bytes. This makes the tool useful when you need to process an existing encoded image and then choose between plain base64 output and a MIME-tagged data URI.
Start with non-empty image data that represents an image rather than a remote image address or unrelated text. The reviewed processing boundary concerns supplied base64 image data, so the input should be prepared in that form before you use the control. The tool can also identify several image formats for the MIME information attached to data-URI output.
A data URI combines a media type with base64 content, which can be useful in a destination that accepts an image data URI. Plain base64 is the more suitable choice when the receiving context expects only the encoded content. Selecting the output style before processing helps you avoid removing or adding a prefix afterward.
Conversion procedure
-
Prepare the base64 text for the image you want to process. Check that the value is not empty and that it is intended to represent image bytes.
-
Enter the prepared value in the image-data input. For non-empty input, the tool base64-decodes the supplied text and attempts to open the resulting bytes as an image.
-
Review the data-URI option before starting. It is enabled by default, so leave it selected when the destination needs a MIME-tagged data URI. Turn it off when the destination calls for the base64 representation without a data URI.
-
Run the conversion and inspect the returned result. A successful response provides base64 text for the original image bytes. When data-URI inclusion is selected, the response also provides a MIME-tagged data URI; when the option is disabled, that data URI string is not produced.
-
Copy the form that matches the receiving context. Keep the media type attached when you use the data-URI form, and pass only the encoded content when the destination expects base64 text alone.
-
If processing is unsuccessful, check the input and try again with non-empty base64 image data that can be opened as an image. An exception during decoding or image opening, or missing image-decoding support, can prevent a successful result. The tool only attempts the image-opening check, so do not use that check as a substitute for independently checking important source data.
Reading the output
The main successful output is a base64 representation of the original image bytes. An enabled data-URI option adds a second form with image MIME information, while disabling that option leaves the data-URI form out of the result. Compare the returned form with what the next application or document is prepared to receive.
PNG, JPEG, WEBP, GIF, and BMP images receive their corresponding image MIME types. If the detected format is absent, the format falls back to PNG and the MIME type becomes image/png. If a detected format is not recognized, the returned format stays as detected while its MIME type falls back to image/png.
An unsuccessful response may reflect empty input, an exception while decoding or opening the image, or unavailable image-decoding support. The decoding step is not configured for strict validation, and the opening step only attempts to open the resulting bytes. Consequently, malformed or partly corrupt data is not guaranteed to be rejected at this boundary. For important use cases, check that the returned value functions correctly where you plan to use it.
Worked example
A developer needs a data-URI-compatible value for a small PNG image in a prototype.
Enter non-empty base64 text for a PNG, leave the data-URI setting enabled, and start processing.
The response contains base64 text for the original PNG bytes and, with the default setting retained, a MIME-tagged data URI using the PNG image type.
Limitations
- The documented boundary handles supplied base64 image data; image-decoding failures and some malformed or partly corrupt inputs can produce an unsuccessful result, while the opening attempt does not guarantee rejection of such content.
- The declared network-access setting is false, but it does not establish how supplied data is stored, retained, deleted, or protected.
Common errors
- An empty input leads to an unsuccessful result; enter non-empty base64-encoded image data and run the conversion again.
FAQ
Does the tool return a data URI?
The result includes one when the data-URI setting is enabled, which is its default state; switching that setting off omits the data URI.
Which image MIME types are recognized?
Supported recognized formats include PNG, JPEG, WEBP, GIF, and BMP, each with its corresponding image MIME type; absent or unrecognized format information follows the documented PNG MIME fallback.
Can I submit an empty value or malformed base64?
An empty value is rejected, whereas non-empty text is decoded and passed to an image-opening attempt; malformed or partially corrupt content is not guaranteed to fail during that boundary check.