Base64 Image Encoder & Decoder
Convert an image to a Base64 data URI, or decode Base64 back to an image — instantly, in your browser. Nothing is uploaded.
What is a Base64 image?
A Base64 image is a picture encoded as a Base64 text string, usually embedded through the data URI scheme. It lets you place an image directly in your HTML or CSS without a separate file request.
How to use this tool
Convert image to Base64
Drag your images into the box above (or click to select them). Encoding starts automatically for JPEG,
PNG, GIF and WebP files. Copy the result as a raw string, an HTML <img> tag or a CSS background.
Convert Base64 to image
Open the Base64 → Image tab, paste the raw Base64 string, choose the image type and press Decode. If the string is valid, the image is shown full-size and can be downloaded.
Where can Base64 images be used?
In the data URI scheme — embedding an image directly in HTML or CSS. This can prevent extra HTTP requests and reduce page load time, and it helps e-mail clients display images in newsletters.
Base64 image code examples (data URI)
HTML — image tag
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABA......" />
CSS — background image
.my-image {
width: 150px;
height: 150px;
background-image: url("data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABA......");
}
PHP — convert image to Base64
function image_to_base64($path) {
$type = pathinfo($path, PATHINFO_EXTENSION);
$image = file_get_contents($path);
return 'data:image/' . $type . ';base64,' . base64_encode($image);
}
C# — convert image to Base64
private string CreateBase64Image(byte[] fileBytes)
{
using (var ms = new MemoryStream())
{
Image img = Image.FromStream(new MemoryStream(fileBytes));
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
return Convert.ToBase64String(ms.ToArray());
}
}
Java — convert image to Base64
public static String encodeToString(BufferedImage image, String type) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
ImageIO.write(image, type, bos);
return Base64.getEncoder().encodeToString(bos.toByteArray());
} catch (IOException e) {
e.printStackTrace();
return null;
}
}