Idan Moshe Idan Moshe - 10 months ago 54
Python Question

Convert (screenshot captured) image to base 64 without saving to png/jpeg in python

I saw a lot of q&a about converting images to base 64 string from image, all of them involving saving the image physically on pc.
What I want is convert the image to base 64 string without the need to save the image physically.

How can I do it with


Answer Source
buffer = io.BytesIO()

im=ImageGrab.grab(), format='PNG')

b64_str = base64.b64encode(buffer.getvalue())