Skip to content

How to turn an image into a Base64 data URI

Convert a picture into a data: URI you can paste into CSS or HTML, in DocFila. The type is read from the file, not its name. On your device.

Convert in DocFila

The short answer

Choose your picture in the Image → Base64 text card of DocFila's Convert hub and save. You get a .txt file holding a data: URI, with the correct image type, ready to paste into a CSS background or an HTML image tag. It runs on your device.

Where does it run?

On this device, offline, for pictures up to 20 MB. Nothing is uploaded.

What is kept, and what changes?

Kept

Changed or lost

What are the steps?

  1. Prepare a small picture. Base64 suits icons and small graphics. Compress or resize a large picture first with the compress-image tool.
  2. Open Image → Base64 text. In Tools choose Convert and open the card, or search the hub for “base64” or “data uri”.
  3. Choose files to convert. Select Choose files to convert and pick the pictures. PNG, JPG, WebP, BMP, GIF and TIFF are accepted.
  4. Convert and save. Start the conversion, then use Save converted file… for one picture, or Save into a folder… for several.
  5. Paste it into your code. Open the .txt, copy the whole line, and use it as src in an img tag or inside url(…) in CSS.

Which options does it offer?

No options. The output is always the data URI for the picture as it is. To change the picture, edit or convert it first, then encode it.

What are the limits?

Up to 20 MB per picture, though a data URI that long is rarely sensible in a page. The file must really be a picture that DocFila reads; a renamed text file is refused. Types outside the list DocFila knows are marked as a generic binary type.

When is another route better?

To make the picture smaller before you encode it, use the Compress to size card, covered on the compress-image tool page. For website icons, the Favicon set card does the whole job. If you need the picture itself rather than text, use PNG to JPG or JPG to PNG.

Questions

What is a data URI?

It is a web address that carries the file itself, written as data:, the type, base64 and the encoded bytes. A browser can show it without fetching a separate file.

Is my picture re-compressed?

No. DocFila encodes the original bytes exactly as they are, without compressing or resizing them again, so the decoded picture is identical to the file you chose at the start.

When should I avoid base64 images?

For anything large. The encoded text is bigger than the file and cannot be cached on its own, so a photograph is better served as a normal image file.

Does it check what type the file is?

Yes. The type is read from the picture's contents, so a PNG renamed to .jpg still gets image/png. A file that is not a picture is refused.

Convert it in DocFila

Free to start, no card needed.