Using the requests library:

import base64
import requests


def get_as_base64(url):

    return base64.b64encode(requests.get(url).content)
Answer from user94559 on Stack Overflow
Discussions

How to convert decode base64 image , in url
I don't think you need the file type info at the beginning of the string. This works for me: base64_str = url.split(',')[1] im = Image.open(BytesIO(base64.b64decode(base64_str))) More on reddit.com
🌐 r/learnpython
1
1
March 13, 2022
Python requests base64 image - Stack Overflow
I am using requests to get the image from remote URL. Since the images will always be 16x16, I want to convert them to base64, so that I can embed them later to use in HTML img tag. import requests More on stackoverflow.com
🌐 stackoverflow.com
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
Converting a dataurl to numpy array
Check out the io module, and the BytesIO class . It behaves like a file handle, so you can read and write to it instead of going through the actual file on the disk. Something like image_bytes = io.BytesIO() image_bytes.write(...) image_bytes.seek(0) # not sure if it's necessary image = Image.open(image_bytes) More on reddit.com
🌐 r/learnpython
2
5
July 7, 2017
🌐
Formspree
formspree.io › blog › image-to-base64
How to Convert an Image URL to Base64 | Formspree
August 28, 2024 - This method is efficient and leverages widely-used, well-supported libraries. To convert image URLs to base64 in Python, you will use the requests library to fetch the image data from a URL.
🌐
IQCode
iqcode.com › code › python › convert-url-to-base64-image-py
convert url to base64 image py Code Example
October 17, 2021 - import base64 import requests def get_as_base64(url): return base64.b64encode(requests.get(url).content) ... Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond. Sign up · Develop soft skills on BrainApps Complete the IQ Test ... convert an image url into base64 data python convert images back from base64 python show image from base64 python online image url to base64 python python image to base64 string python encode image to base64 string PYTHON send base64 encode image python turning image into base64 string python make image base64 url format python m
🌐
C# Corner
c-sharpcorner.com › article › converting-image-to-base64-in-python
Converting Image To Base64 In Python
March 16, 2023 - Next, we can convert the image to base64 format using Python's "base64" module.
🌐
CodeSpeedy
codespeedy.com › home › convert image to base64 string in python
Convert Image to Base64 String in Python - CodeSpeedy
September 19, 2023 - import pybase64 with open("my_image.jpg", "rb") as img_file: my_string = pybase64.b64encode(img_file.read()) print(my_string) ... As you can see here, your string has been printed. But in starting position of your base64 string there is a b’
🌐
Bobby Hadz
bobbyhadz.com › blog › convert-image-to-base64-string-in-python
Convert an Image to Base64 String and vice versa in Python | bobbyhadz
April 11, 2024 - Use the file.read() method to read the image's contents. Use the base64.b64encode() method to encode the bytes using Base64 and return a bytes-like object.
🌐
GitHub
gist.github.com › alexmill › d71b67ed84fd0150db2c
Create a base64 thumbnail from image URL (Python) · GitHub
Save alexmill/d71b67ed84fd0150db2c to your computer and use it in GitHub Desktop. Download ZIP · Create a base64 thumbnail from image URL (Python) Raw · img2base64.py · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below.
Find elsewhere
🌐
Blogger
opentechlabs.blogspot.com › 2016 › 09 › convert-image-to-base64-encoding-python.html
Convert Image to Base64 Encoding - Python | OpenTechLabs
September 21, 2016 - import base64 import requests url = "http://images.freeimages.com/images/previews/118/bicycle-sign-3-1442216.jpg" response = requests.get(url) convertedData = ("data:" + response.headers['Content-Type'] + ";" + "base64," +str(base64.b64enco...
🌐
Base64.Guru
base64.guru › home › base64 converter › base64 encode
Image to Base64 | Base64 Encode | Base64 Converter | Base64
The Image to Base64 converter generates ready-made examples, depending on the selected output format. It automatically detects the content type of the uploaded image, so that you simply copy the complete result.
🌐
Cloudinary
cloudinary.com › home › image conversion to base64 in python: a comprehensive guide
Image Conversion to Base64 in Python: A Comprehensive Guide | Cloudinary
April 24, 2026 - Alternatively, you can convert images to Base64 directly in Python with the Base64 package included in the Python Standard Library.
🌐
GitHub
gist.github.com › aspose-com-gists › efc06400b0b5e15918b2f302ff88cd0e
Convert Image to Base64 in Python · GitHub
Learn more about clone URLs · Clone this repository at <script src="https://gist.github.com/aspose-com-gists/efc06400b0b5e15918b2f302ff88cd0e.js"></script> Save aspose-com-gists/efc06400b0b5e15918b2f302ff88cd0e to your computer and use it in GitHub Desktop. Download ZIP · Convert Image to Base64 in Python ·
🌐
Reddit
reddit.com › r/learnpython › how to convert decode base64 image , in url
r/learnpython on Reddit: How to convert decode base64 image , in url
March 13, 2022 -
https://8c97-106-213-197-139.ngrok.io/mynsfw/predict?lnk=data:image/jpeg;base64,/9j/4AAQSkZ..................CESAf/2Q==

Link to the full request

When i get a request like this on my flask server , how do i get image out of "lnk".

If there is better way to receive the link to flask let me know that too , i can make those changes too.

What i have tried

bs64_rg=re.compile(r'data:image\/([a-zA-Z]*);base64,([^\"]*)')
# bts_io=BytesIO()
try:
        
        url=(request.args.get('lnk'))
        bs64=bs64_rg.search(url)
        if bs64:
            
            r=bs64.group(2)
            r=base64.b64decode(r)
            
            # bts_io.write(r)
            # img=Image.open(bts_io.write(r))
            # bts_io.truncate(0)
            # bts_io.seek(0)
            # img = Image.open(BytesIO(r))
            img = image.img_to_array(image.load_img(BytesIO(r),target_size=(224,224))) / 255.

My try , please ignore the lot of commented stuff

🌐
PixelPanda
pixelpanda.ai › home › free tools › image to base64
Image to Base64 — Convert Any Image to Base64 Online Free | PixelPanda
... This tool handles one image at a time. For batch conversion, use a script: in Python, loop through files with base64.b64encode(). In Bash: for f in *.png; do base64 "$f" > "$f.b64"; done. For a quick web approach, convert ...
🌐
Reddit
reddit.com › r/pythonprojects2 › how to convert image to base64 in python?
r/PythonProjects2 on Reddit: How to convert image to base64 in Python?
October 27, 2024 - Converting an image to Base64 is straightforward in Python, and you don’t need any external libraries because Python provides everything through its built-in base64 module.
🌐
AskPython
askpython.com › home › encoding an image file with base64 in python
Encoding an Image File With BASE64 in Python - AskPython
April 29, 2023 - Base64 is a system of encoding that converts bytes to ASCII characters. The system contains all the upper case and lower case alphabets of the English lexicon, the “+” and “/” characters and numbers from 0(zero) to 9(nine). The base64 module in Python enables the conversion of strings, text files, and media files such as images, videos, or audio files into Base64 characters.
🌐
Medium
annacsmedeiros.medium.com › efficient-image-processing-in-python-a-straightforward-guide-to-base64-and-numpy-conversions-e9e3aac13312
Efficient Image Processing in Python: A Straightforward Guide to Base64 and Numpy Conversions | by Anna C S Medeiros | Medium
March 30, 2024 - This guide aims to equip you with the technical skills to handle image data, emphasizing Lossless Compression and accurate data representation in Python. import base64 with open("image.jpg", "rb") as image_file: buffer = image_file.read() img_base64 ...