Display clipboard image in iPython notebook
Often when I'm using the iPython notebook, I have to take a screenshot and place it inline. I created the following code to quickly display the contents of my clipboard, assuming I just Alt+PrintScreen'd or have some other image copied.
from PIL import ImageGrab
from IPython.display import display, Image
def save_show_clip(ratio=1.0):
im_data = ImageGrab.grabclipboard()
new_size = tuple([int(i*ratio) for i in im_data.size])
thumb = im_data.resize(new_size)
fn = "temp.PNG"
thumb.save(fn)
img = Image(filename=fn)
display(img)
save_show_clip(.3)
Written by Cloud Cray
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#