Toolvito

Works on this device

Image Encoding Converter

Open an image to get its Base64 text or a data URL, or paste Base64 to get the image file back. You can also save the image again as PNG, JPEG or WebP and compare the sizes. The image is read and written by this browser on your device.

Your image

Ready. The image is read by this browser and is not sent anywhere.

PNG, JPEG, GIF, WebP, BMP, ICO, AVIF or SVG, up to 20 MB.

Such as data:image/png;base64,iVBORw0KGgo... Plain Base64, URL-safe Base64 and text inside CSS url("...") or an HTML src="..." work too.

The image

Open an image or paste its Base64 to see it here.

As text

Open a picture first.

Save in another format

From 1 to 100. Higher keeps more detail and gives a larger file.

JPEG has no see-through pixels.

The new file has only the pixels: EXIF data, comments and colour profiles are dropped. The picture is written by this browser and is not sent anywhere.

How to use the image encoding converter

  1. To turn an image into text, choose Open an image from your device and pick a PNG, JPEG, GIF, WebP, BMP, ICO, AVIF or SVG file.
  2. To turn text into an image, paste Base64 or a data URL into the box and choose Read the text. Text inside CSS url("...") or an HTML src="..." is found too. Spaces and line breaks are left out.
  3. Under As text, choose the form: Base64 only, a data URL, a CSS background or an HTML img tag. Choose Copy the text or Download the text.
  4. Choose Download the image file to save the bytes of the open image, for example after you pasted Base64.
  5. Under Save in another format, choose PNG, JPEG or WebP and a quality, then Convert. The page shows the size before and after, and the pixel size of the new file. Choose Download the new file.

How the conversion works

  • Base64 writes every 3 bytes as 4 characters from A to Z, a to z, 0 to 9, + and / (RFC 4648). So the text is about one third larger than the file: its length is 4 × (bytes ÷ 3, rounded up).
  • A data URL is data:, the media type, ;base64, and the Base64 (RFC 2397). A web page can use it in place of the address of an image file.
  • The format of a file is found from its first bytes, not from its name. A PNG starts with the bytes 89 50 4E 47, a JPEG with FF D8 FF, a GIF with "GIF8", a WebP with "RIFF" and "WEBP".
  • To save in another format, the browser decodes the picture, draws its pixels and writes them again (canvas toBlob). JPEG and WebP use the quality you choose; PNG is lossless. JPEG has no see-through pixels, so they are laid on white or black.
  • After the conversion, the page reads the first bytes of the new file again. If a browser cannot write the format you asked for, it gives a PNG instead, and the page says so.

What changes when you convert

  • The new file has only the pixels. Metadata is dropped: EXIF data such as the camera, the date and the place, comments and colour profiles are not copied.
  • A photo with an orientation in its EXIF data is shown turned the right way, and the new file is written that way.
  • Only the first frame of an animated GIF or WebP is kept.
  • JPEG and WebP at a quality below 100 lose some detail, and converting again loses a little more each time. Keep your original file.
  • Encoding as Base64 or a data URL changes nothing in the picture: decoding the text gives back the same bytes.

Worked example

Choose Try an example. The example is a PNG of 64 × 48 pixels written without compression: 12,404 bytes. Its Base64 has 4 × (12,404 ÷ 3, rounded up) = 4 × 4,135 = 16,540 characters, and its data URL adds the 22 characters of data:image/png;base64, for 16,562 in all.

Convert it to WebP, JPEG or PNG and the new file is much smaller, because the browser compresses the pixels. The exact size depends on the browser. The see-through blue part becomes light blue on white in JPEG.

The same in code

Programs make the same Base64 from the bytes of a file. In a browser, FileReader.readAsDataURL(file) gives a data URL. In Node.js, fs.readFileSync(path).toString("base64") gives Base64. In Python, base64.b64encode(open(path, "rb").read()) gives Base64. To turn Base64 back into bytes: Buffer.from(text, "base64") in Node.js and base64.b64decode(text) in Python.

Limits you should know

  • Files of up to 20 MB, and pictures of up to 8,192 pixels on a side and 16,777,216 pixels in all for a conversion.
  • The browser decides which formats it can show and write. Most browsers cannot show TIFF or HEIC pictures; the page names the format and refuses the file. Browsers write only PNG, JPEG and WebP from a canvas.
  • A text of more than 2,000,000 characters is not shown in the box, but you can copy it and download it.
  • An SVG picture needs a width and a height to be converted. Some browsers do not allow an SVG to be written to another format.
  • This page does not edit, resize or compress a picture beyond the quality setting. For colours of a picture, use the Color Picker. For Base64 of text, use the Base64 Encoder & Decoder. For the bytes of a file in hexadecimal, use Binary Blob to Hex.

Related tools