Image encoding guides

Choose between raw Base64 and an image data URL

·

Convert an image file into text you can copy. Choose Image data URL for an image source field or Raw Base64 for a field that expects only encoded bytes.

Image to Base64

Estimate the exact payload size

Base64 represents three input bytes with four characters. A 1,025-byte PNG needs 4 × ceil(1,025 ÷ 3), or 1,368 characters. A PNG data URL adds the 22 characters in its header, for a total of 1,390. The same source bytes appear in both forms.

RFC 2397, The data URL scheme

Check a round trip

Copy the generated text to Base64 to Image and download the restored file. Compute the SHA-256 hash of both the source and the download in the file checksum tool. Matching hashes confirm that the image bytes, including any embedded metadata, survived the round trip.

Choose between embedding and a separate file

A 30,000-byte image needs 40,000 Base64 characters before the data URL header. If the receiving text field accepts at most 32,000 characters, encoding that original cannot fit. Resize or compress the image first if its dimensions permit.

If the destination asks for raw Base64, copy the payload only. If it expects an image URL, keep the full header. Decode a trial copy and compare the recovered size with the original before migrating many images.

Common questions

Why is the text larger than the image file?

Each Base64 character represents six bits. A complete group of three input bytes requires four characters, plus padding in the final group when needed.

Can I use this to remove photo metadata?

The encoding preserves embedded metadata. Remove unwanted metadata from a copy of the image before encoding it.

Sources

Put it into practice.

Related guides