This should do it in Python:
import base64
binary_fc = open(filepath, 'rb').read() # fc aka file_content
base64_utf8_str = base64.b64encode(binary_fc).decode('utf-8')
ext = filepath.split('.')[-1]
dataurl = f'data:image/{ext};base64,{base64_utf8_str}'
Thanks to @cnst comment, we need the prefix data:image/{ext};base64,
Thanks to @ramazanpolat answer, we need the decode('utf-8')
Related Contents:
- Convert RGB color to English color name, like ‘green’ with Python
- Is embedding background image data into CSS as Base64 good or bad practice?
- How do I get the picture size with PIL?
- Saving a Numpy array as an image
- Why do I need ‘b’ to encode a string with Base64?
- How do you decode Base64 data in Python?
- matplotlib: how to draw a rectangle on image
- How to resize an image with OpenCV2.0 and Python2.6
- Numpy Resize/Rescale Image
- In Python, how do I read the exif data for an image?
- Extract a page from a pdf as a jpeg
- Image library for Python 3
- how to convert an RGB image to numpy array?
- Python OpenCV2 (cv2) wrapper to get image size?
- Invert image displayed by imshow in matplotlib
- Add Text on Image using PIL
- How to reduce the image file size using PIL
- Extract images from PDF without resampling, in python?
- How does one convert a grayscale image to RGB in OpenCV (Python)?
- python save image from url
- PIL “IOError: image file truncated” with big images
- How to use PIL to make all white pixels transparent?
- Application not picking up .css file (flask/python) [duplicate]
- Convert png to jpeg using Pillow
- Why does Tkinter image not show up if created in a function?
- How can I obtain the image size using a standard Python class (without using an external library)?
- Combine 3 separate numpy arrays to an RGB image in Python
- what does this mean ? image/png;base64? [duplicate]
- How to convert base64 string to image? [duplicate]
- Detect and visualize differences between two images with OpenCV Python
- How to convert an integer to the shortest url-safe string in Python?
- How to encode text to base64 in python
- TypeError: Image data can not convert to float
- How do I increase the contrast of an image in Python OpenCV
- Python OpenCV load image from byte string
- How do you directly overlay a scatter plot on top of a jpg image in matplotlib / Python?
- Flask css not updating [closed]
- How do I read an image file using Python? [closed]
- Decoding base64 from POST to use in PIL
- How to override css in Django Admin?
- PIL: Convert Bytearray to Image
- OpenCV Error: (-215)size.width>0 && size.height>0 in function imshow
- Showing an image from console in Python
- How to scale images to screen size in Pygame
- Add padding to images to get them into the same shape
- Normalizing images in OpenCV produces black image?
- How to read images into a script without using using imageio or scikit image?
- Compare two images the python/linux way
- Python OpenCV convert image to byte string?
- No module named Image