code: def display_pil_image(im):
     
     from IPython.core import display
     b = BytesIO()
     im.save(b, format='png')
     data = b.getvalue()
  
     ip_img = display.Image(data=data, format='png', embed=True)
     return ip_img._repr_png_()
docs: Displayhook function for PIL Images, rendered as PNG.