I'm not sure I understand your question. I assume you are doing something along the lines of:

import base64

with open("yourfile.ext", "rb") as image_file:
    encoded_string = base64.b64encode(image_file.read())

You have to open the file first of course, and read its contents - you cannot simply pass the path to the encode function.

Edit: Ok, here is an update after you have edited your original question.

First of all, remember to use raw strings (prefix the string with 'r') when using path delimiters on Windows, to prevent accidentally hitting an escape character. Second, PIL's Image.open either accepts a filename, or a file-like (that is, the object has to provide read, seek and tell methods).

That being said, you can use cStringIO to create such an object from a memory buffer:

import cStringIO
import PIL.Image

# assume data contains your decoded image
file_like = cStringIO.StringIO(data)

img = PIL.Image.open(file_like)
img.show()
Answer from Jim Brissom on Stack Overflow
🌐
Base64 Image Encoder
base64-image.de
Convert Images to Base64 Online — Free Encoder & Optimizer | base64-image.de
Drag and drop your images onto this page (or click to select files), and they are uploaded securely via HTTPS to our server. Each image is read, optionally compressed and resized, then encoded to a base64 string.
🌐
Base64.Guru
base64.guru › home › base64 converter › base64 encode
Image to Base64 | Base64 Encode | Base64 Converter | Base64
Please note that the image to Base64 encoder accepts any images types with a size of up to 50 MB.
Discussions

python - Encoding an image file with base64 - Stack Overflow
I want to encode an image into a string using the base64 module. I've ran into a problem though. How do I specify the image I want to be encoded? I tried using the directory to the image, but that ... More on stackoverflow.com
🌐 stackoverflow.com
Is it a good idea to convert images into base64 string and save them in database?
You will get many people saying don't because if not implemented well it can bite ya. Don't be concerned about "optimal", tell yourself "good enough" and "don't let perfect be the enemy of good". But I have done this for several projects (enterprise, mission critical systems) and it works just fine. From the developer standpoint I love it. When I yank the "byte array" from the DB I can just pass it right to the client as-is, just adding on the mime type, super simple. Right now I have a system that stores photos of students at a university and we serve those out with an API. All done in C# and SQL Server. We have probably 50,000 photos and it is lighting fast. That being said I have also stored files in S3 and just stored the name in the DB. I will usually rename the file so S3 stores it efficiently. I like things like s3 better than a file system since you can dedicate a bucket just to this and some sysadmin won't go mucking around. I agree with you on storing the unstructured binary data along with your structured data for simplicity. I had a project once that wrote images to a filesystem. Years later older images were lost due to some file system cleanup process. Over my 25 years programming I have found you cannot guess where the issues will be. Don't optimize until you measure it. If you can build a proof of concept then hammer it, do it. Write a script that inserts and reads images and loop it for a few hours. See what happens. Also if you implement something and a few years later it starts to falter, then refactor. But you need to monitor! This is another place where people get bit, they do something like this and just let it run in a corner until it "just dies for no reason" one day. You or someone needs to care and feed for it. I am going to assume on-prem Microsoft SQL Server, your usage may vary. Use "VARBINARY(MAX)" for the field type https://docs.microsoft.com/en-us/sql/t-sql/data-types/binary-and-varbinary-transact-sql?view=sql-server-ver15 Put it in a table by itself with an id to look it up. Store filename, and filetype(mime-type) too if needed. Slap an index on the id, reference that id in other tables. Critical: Put the table in its own filegroup separate from the other tables. This will allow for faster restores since you can restore the primary filegroup and get your DB back online ASAP, then as it is up and running restore the filegroup with the images. So instead of the whole DB being down for hours, it is up in minutes with only the images being unavailable for hours. https://docs.microsoft.com/en-us/sql/relational-databases/databases/database-files-and-filegroups?view=sql-server-ver15 As with all DBs the filegroups should not be on the system (C) drive, maybe even put the images table filegroup on its own drive with nothing else. Do set a limit on the incoming filesize in your code. Someone could send in a few Blu-ray ISOs and cripple your system. In .NET code you store the image data in a byte array "byte[] " variable. That byte array is what is stored in the varbinary(max) DB field. It is easy to convert the incoming image/file to byte[], just google around for that there are many easy to do it. Design and implement a cleanup process and purge old unneeded records. No one ever seems to do this and the data grows forever until the system is retired/migrated. For small DBs it's not a problem but for this you must go back to your stakeholder and get in writing when you can delete old records then set an automated process or scheduled manual progress to do it. If they need the data long term maybe older data can be moved out of the online system and to an archive or warehouse. Microsoft has some other methods that I have not used. Check those out. https://docs.microsoft.com/en-us/sql/relational-databases/blob/binary-large-object-blob-data-sql-server?view=sql-server-ver15 -- Good luck More on reddit.com
🌐 r/dotnet
111
46
April 28, 2022
How to convert local image into base64 encoding
I am using API to create test execution with evidence attaching as well. So, used prerequiste tab to generate base64 encoded which used in data in evidence tag. I am facing issues in prerequiste script. unable to upload attachment and even evidence attached getting error ‘The requested content ... More on community.postman.com
🌐 community.postman.com
5
0
December 6, 2023
When to use Base-64 encoded images?
I mainly use them for 404 and 500 pages. It's usually a good idea to build your error pages with inline css and base-64 images. Since some errors on the server could prevent the browser from getting the css and image files, you're still able to present the user with a functional HTML page. More on reddit.com
🌐 r/webdev
17
17
November 14, 2012
People also ask

Does Base64 encoding affect Image image quality?
No. Base64 is a lossless encoding scheme – it only changes how data is represented, not the data itself. The decoded image is byte-for-byte identical to the original. Quality loss can only occur if you compress the source Image image before encoding.
🌐
products.aspose.com
products.aspose.com › svg › .net › image-to-base64
Convert Image to Base64 – Online Encoder and C# Code
Can I copy or download the Base64 string after encoding?
Yes, the tool provides built-in Copy and Download buttons. You can instantly copy the output string or download it as a text file for future use in projects or documentation.
🌐
plerdy.com
plerdy.com › home › image to base64 encoder
Image to Base64 Encoder – Plerdy
How does the Plerdy Image to Base64 Encoder work?
The encoder takes your uploaded image, processes its binary data, and converts it into a Base64 text string. This lets you embed images directly into HTML, CSS, or emails without linking external files. For many teams, this is the fastest way to use a base 64 encode image workflow without worrying about CDN delays.
🌐
plerdy.com
plerdy.com › home › image to base64 encoder
Image to Base64 Encoder – Plerdy
🌐
Elmah.io
elmah.io › tools › base64-image-encoder
Base64 Image Encoder - Convert any image file or URL online
With elmah.io's free image to Base64 encoder, it's easy to copy and paste markup or style for exactly your codebase. Simply drag and drop, upload, or provide an image URL in the controls above and the encoder will quickly generate a Base64 encoded ...
🌐
Base64 Encode
base64encode.org
Base64 Encode and Decode - Online
Base64 encoding schemes are commonly used when there is a need to encode binary data, especially when that data needs to be stored and transferred over media that are designed to deal with text.
Find elsewhere
🌐
Sentry
sentry.io › sentry answers › html › how do i display a base64 image in html?
How do I display a Base64 image in HTML? | Sentry
January 15, 2024 - To manually convert an image, use a site like http://base64online.org/encode.
🌐
Plerdy
plerdy.com › home › image to base64 encoder
Image to Base64 Encoder – Plerdy
December 8, 2025 - It grabs the binary data (all the 1s and 0s), slices it into chunks, and turns it into a readable string. Boom! Your image is now text. Tools like Plerdy’s encoder do this super fast—no waiting, no hassle. Just hit "Convert" and grab the result. Easy, right? Let’s get real. Base64 isn’t perfect, but it has its moments.Want an example?
🌐
Aspose
products.aspose.com › svg › .net › image-to-base64
Convert Image to Base64 – Online Encoder and C# Code
January 1, 2021 - In order to convert Image to Base64 string, we use Aspose.SVG for .NET API, which is a feature-rich, powerful, easy-to-use document manipulation API for the C# platform. We consider the example of PNG Image to Base64 encoding and embedding Base64 string as data URI into an SVG document.
🌐
YouTube
youtube.com › watch
2.6 Saving Images and Base64 Encoding - Working with Data ...
💻https://github.com/CodingTrain/Intro-to-Data-APIs-JS Let's add an image from the webcam to our database. For this project, we will be using the p5.js JavaS...
Published: June 6, 2019
🌐
YouTube
youtube.com › watch
Power Apps Convert Image to Base64 for Emails, PDFs and Components - YouTube
In this video, you will learn how to covert images so you can use them through out your app in their encoded form. This makes Components more flexible, PDF c...
Published: June 26, 2020
🌐
Wikipedia
en.wikipedia.org › wiki › Base64
Base64 - Wikipedia
July 30, 2026 - Encoding an attachment as Base64 before sending, and then decoding when received, assures older SMTP servers correctly transmit messages with attached binary information. ... For example, to include the data of an image in a script to avoid depending on external files.
🌐
Jam
jam.dev › utilities › image-to-base64
Image to Base64 Converter | Free, Open Source & Ad-free
Converting an image to base64 changes the image data. You can include this format directly in your code. You can even use the img src attribute with base64-encoded data.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Glossary › Base64
Base64 - Glossary | MDN
Base64 encoding schemes are commonly used to encode binary data for storage or transfer over media that can only deal with ASCII text (or some superset of ASCII that still falls short of accepting arbitrary binary data). This ensures that the data remains intact without modification during ...
🌐
Swimburger
img2base64.swimburger.net
Online base64 image encoder
Convert any file to base64 — entirely in your browser, nothing uploaded.
🌐
FLOGVIT
image.flogvit.com › en › tools › base64
Base64 Image Encoder | FLOGVIT Image Tools
Free base64 image encoder and decoder. Convert images to base64 strings for embedding in HTML, CSS, and code. Decode base64 back to images.
🌐
Tools
tools.designzig.com › base64-image-encoder
Base64 Image Encoder | DesignZig
Base64 encoding converts binary image data into ASCII text format, allowing you to embed images directly in HTML or CSS without external file references.
🌐
Postman
community.postman.com › help hub
How to convert local image into base64 encoding - Help Hub - Postman Community
December 6, 2023 - I am using API to create test execution with evidence attaching as well. So, used prerequiste tab to generate base64 encoded which used in data in evidence tag. I am facing issues in prerequiste script. unable to uploa…
🌐
NVIDIA
docs.nvidia.com › nim › vision-language-models › latest › examples › kimi-k2.6 › api.html
Query the Kimi-K2.6 API
April 22, 2026 - Part of NVIDIA AI Enterprise, NVIDIA NIM microservices are a set of easy-to-use microservices for accelerating the deployment of foundation models on any cloud or data center and helps keep your data secure. NIM microservices have production-grade runtimes including on-going security updates.
🌐
Face Comparison
facecomparison.toolpie.com
Face Comparison / Face Similarity Test Online
Image to Base64 Encoder · Base64 to Image Decoder · Car Model Recognition · Email to Image · Text to Image · Color Space Conversion · Days Between Dates · Date Calculator · Morse Code Translator · Landmark Image Recognition · Online OCR · Simplified-Traditional Chinese Translation ·