from PIL import Image
import base64
import io
with open("img.png", "rb") as f:
b64str = base64.b64encode(f.read())
data = f"data:image/png;base64,{b64str.decode()}"
data2 = b64str.decode()
imagedata = base64.b64decode(data2)
buf = io.BytesIO(imagedata)
img = Image.open(buf)
print(img)
#https://stackoverflow.com/questions/273946/how-do-i-resize-an-image-using-pil-and-maintain-its-aspect-ratio
img.size
img.width
img.height
size = 128, 128
display(img)
img.thumbnail(size, Image.ANTIALIAS)
display(img)
img.save('img2.png', 'PNG')
img2 = Image.open("imgW.png")
display(img2)
img2.thumbnail(size, Image.ANTIALIAS)
display(img2)