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
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.
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.
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.
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.
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.
<html><body> <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABA......" /> </body></html>
<style type="text/css" > div.my-image { width:150px; height:150px; background-image: url("data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABA......"); } </style>
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); }
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()); } }
/** * 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; }