Image To Base64 Encoder

Result image

About this tool

This tool helps you to convert your image to base64 string. You can upload your image from a local computer or give the tool a URL to an image file on the internet then the tool will give you a base64 encoded string.

In addition, the tool also provide you appropriate data URI, code snippets to embed your image into a HTML file as well as a CSS file.

We also provide: Base64 Encoder, Base64 Decoder

HTML code snippet

Copy the code snippet and paste it in a HTML file to render your image.

CSS code snippet

Copy the code snippet and paste it in a CSS file to render your image.

About Base64

Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The term Base64 originates from a specific MIME content transfer encoding.

Base64-encoded data takes about 33% more space than the original data.

Each base64 digit represents exactly 6 bits of data. Three 8-bit bytes (i.e., a total of 24 bits) can therefore be represented by four 6-bit base64 digits.

The particular set of 64 characters chosen to represent the 64 place-values for the base varies between implementations. The general strategy is to choose 64 characters that are both members of a subset common to most encodings, and also printable. This combination leaves the data unlikely to be modified in transit through information systems, such as email, that were traditionally not 8-bit clean.[1] For example, MIME's Base64 implementation uses A–Z, a–z, and 0–9 for the first 62 values. Other variations share this property but differ in the symbols chosen for the last two values; an example is UTF-7.

The earliest instances of this type of encoding were created for dialup communication between systems running the same OS — e.g., uuencode for UNIX, BinHex for the TRS-80 (later adapted for the Macintosh) — and could therefore make more assumptions about what characters were safe to use. For instance, uuencode uses uppercase letters, digits, and many punctuation characters, but no lowercase.

Source: Wikipedia.

PHP - Encodes data with MIME base64

$image = file_get_contents("/path/to/image.jpg");
$base64 = base64_encode($imagedata);

Java 8 - Base64 Encoding

import java.io.File;
import java.util.Base64;
public class Application {
  public static void main(String args[])
  throws Exception {
    File file = new File("/path/to/image.jpg");
    byte image[] = new byte[(int) file.length()];
    aStream.read(imageData);
    String base64Str = Base64.getEncoder()
      .encodeToString(image);
    // Output base64Str
  }
}