Base64 Image

Select or Drop images here and the Base64 encoding will be started automatically.

Encode image to Base64 without size or number limitation.

File API & FileReader API not supported

Download YouTube Thumbnail / Random Color / Webcam Test / Loop YouTube videos / Search on Instagram by location

Dear Base64 Image user! We have made some Bug Fixes!

The forgotten double quote on the end of base64 string was removed!
The img HTML tag copy was repaired!
To be sure you have the bug fixes, please reload the page with CTRL+F5 or erase the catch of your browser.

What is Base64 Image?

It is a webtool to encoding image to Base64 and to decode Base64 to image if it is possible.
The result of the encoding is displayed in Base64 format.
The Base64 string can be copied to the clipboard as CSS background property or HTML img tag format.

How to use Base64 Image?

Convert Image to Base64

It is very simple! Drag the selected images into the white rectangle on the top of the page and the encoding will be started automatically.
The selected images must be in JPEG, GIF or PNG format.

Convert Base64 to Image

Push the "Convert to Base64 Image" button on the top of the page.
Put the raw Base64 string into the textarea, select the type of the image (JPEG,PNG,GIF) and push the "Decode" button.
If the Base64 string is a valid image it will be displayed in full size.

Where can be used Base64 encoded image?

It can be used in Data URI scheme.
With this technique you can prevent multiple HTTP requests, reducing the loading time of a web page.
By using Data URI scheme you can force the e-mail client to display your images sent via e-mail. This is very helpful in newsletters.

Examples for usage of Base64 encoded image with Data Uri

Html example - Image tag

   
 <html><body>
    <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABA......" />
</body></html>
                

CSS example - Background image

   
 <style type="text/css" > 
 div.my-image { width:150px;
                height:150px; 	
                background-image: url("data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABA......");
              }
 </style>
                

PHP example - convert image to Base64 string

  
function image_to_base64($path_to_image)
{ 
    $type = pathinfo($path_to_image, PATHINFO_EXTENSION);
    $image = file_get_contents($path_to_image);
    $base64 = 'data:image/' . $type . ';base64,' . base64_encode($image);
}
                

C# example - method for convert image to Base64 string

 private string CreateBase64Image(byte[] fileBytes)
 {
        Image streamImage;
      
        using (MemoryStream ms = new MemoryStream(fileBytes))
        {
            /* Create a new image, saved as a scaled version of the original */
            streamImage = ScaleImage(Image.FromStream(ms));
        }
        using (MemoryStream ms = new MemoryStream())
        {
            /* Convert this image back to a base64 string */
            streamImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            return Convert.ToBase64String(ms.ToArray());
        }
 }
                

JAVA example - method for convert image to Base64 string

    /**
     * Encode image to Base64 string
     * @param image The image to Base64 encode
     * @param type jpeg, bmp, ...
     * @return Base64 encoded string
     */
    public static String encodeToString(BufferedImage image, String type) {
        String imageString = null;
        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        try {
            ImageIO.write(image, type, bos);
            byte[] imageBytes = bos.toByteArray();

            BASE64Encoder encoder = new BASE64Encoder();
            imageString = encoder.encode(imageBytes);

            bos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return imageString;
    }