Python JPEG Image to Base64 String Example
Hey Dev,
This post is focused on how to convert jpeg to base64 in python. This example will help you python convert jpg image to base64. We will look at an example of how to convert jpg image to base64 string in python. I am going to show you about how to decode jpeg image to base64 string in python.
If you are looking to convert jpg image to base64 string in python then I will help you with that. I will give you a very simple example, we will take one jpg image "image.jpg" and then convert it into the base64 string. we will use base64 library. So, without further ado, let's see simple examples: You can use these examples with python3 (Python 3) version.
Example:
main.py
# Import base64 Module import base64 # Python Convert Image to Base64 String with open("image.jpeg", "rb") as imageFile: encodedString = base64.b64encode(imageFile.read()) print(encodedString);
Output:
JVBERi0xLjMNCiXi48/TDQoNCjEgMCBvYmoNCjw8DQovVHlwZSAvQ NCjw8DQovVHlwZSAvQ2F0YWxvZw0KL091dGxpbmVzIDIgM 48/TDQoNCjEgMCBvYmoNCjw8DQovVHlwZSAvQ2F0YWxvZw0KL091dGxpbmV QoNCjEgMCBvYmoNCjw8DQ......
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Convert Image to Base64 String in Python?
- Python Convert base64 String to JPEG Image Example
- Python Convert base64 String to PNG Image Example
- How to Convert base64 to PDF in Python?
- How to Convert base64 to Image in Python?
- How to Convert Image to Base64 in Laravel?
- How to Create and Write Xlsx File in Python?
- How to Read a JSON File in Python?
- How to Get Column Names from CSV File in Python?
- Python Read CSV File Without Header Example
- How to Add Element at the End of List in Python?
- How to Subtract Months to Date in Python?