The fastest way to preview PIL images

Now I am working with PIL images in Python. What is the fastest way to view a PIL image in a Python shell? Saving a file and then opening it in my OS is rather cumbersome.

+7
source share
3 answers

The Image class has a show (self, title=None, command=None) method show (self, title=None, command=None) that you can use.

+2
source

After installing iPython and PyQT , you can display the PIL images in the ipython qtconsole line after executing the following code:

 # display_pil.py # source: http://mail.scipy.org/pipermail/ipython-user/2012-March/009706.html # by 'MinRK' import Image from IPython.core import display from io import BytesIO def display_pil_image(im): """displayhook function for PIL Images, rendered as PNG""" 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_() # register display func with PNG formatter: png_formatter = get_ipython().display_formatter.formatters['image/png'] png_formatter.for_type(Image.Image, display_pil_image) 

Usage example:

 import Image import display_pil im = Image.open('test.png') im 

ipython qtconsole display the loaded image in a row.

+3
source

I would recommend using iPython instead of the vanilla python interpreter. Then you can easily use the matplotlib.pyplot.imshow function, and with the Qt console, you can even get images built in a string in the interpreter.

enter image description here

+2
source

All Articles