import import PySimpleGUI as sg from PIL import Image from io import BytesIO def disp_image(val: str) -> Union[None, str]: """Arg: url of image, Returns .png image for use in PySimpleGUI""" try: image = Image.open(requests.get(val, stream=True).raw) image.thumbnail((300, 300)) # resize as required bio = io.BytesIO() image.save(bio, format='PNG') return bio.getvalue() except requests.exceptions.RequestException as e: return f"Error {e}" """Example of use""" layout = [[sg.Image(data=disp_image(vals.image))]]