A way to convert image directly from url to base64 without saving as a python file

I want to convert a web image to base64. I know how to do this now, saving the image as a .jpg file, and then using the base64 library to convert the .jpg file to a base64 string.

I am wondering if I can skip the image save step first?

Thank!

+4
source share
1 answer

Using the requests library :

import base64

import requests

def get_as_base64(url):
    return base64.b64encode(requests.get(url).content)
+12
source

Source: https://habr.com/ru/post/1648078/


All Articles