changed convert_to_bytes function to use a context manager for better memory management

This commit is contained in:
PySimpleGUI 2020-07-25 17:45:19 -04:00
parent 50c7903aa9
commit 7731b07f1f
2 changed files with 15 additions and 9 deletions

View file

@ -891,10 +891,10 @@ def convert_to_bytes(file_or_bytes, resize=None):
new_width, new_height = resize
scale = min(new_height/cur_height, new_width/cur_width)
img = img.resize((int(cur_width*scale), int(cur_height*scale)), PIL.Image.ANTIALIAS)
bio = io.BytesIO()
img.save(bio, format="PNG")
del img
return bio.getvalue()
with io.BytesIO() as bio:
img.save(bio, format="PNG")
del img
return bio.getvalue()