Paul St George
Posts: 3
Joined: Thu May 24, 2018 6:29 pm

PIL show() method

Fri May 25, 2018 10:56 am

I am using the Python Imaging Library (PIL), Python 2 and Raspberry Pi 3 B+

My code is simply:

Code: Select all

from PIL import Image

im = Image.open(‘somepic.jpg’)
im.show() # display image

But the show() method looks for the default viewer (probably xv). How do I change this (in the code, or in some settings) to a different viewer (of my choice).

User avatar
scruss
Posts: 1731
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: PIL show() method

Fri May 25, 2018 11:26 am

You've got Hobson's choice on this:

Code: Select all

     |  show(self, title=None, command=None)
     |      Displays this image. This method is mainly intended for
     |      debugging purposes.
     |      
     |      On Unix platforms, this method saves the image to a temporary
     |      PPM file, and calls either the **xv** utility or the **display**
     |      utility, depending on which one can be found
It's most likely using ImageMagick's display command, as I haven't seen xv around for years. The only potential change you could make is to use GraphicsMagick instead of IM, but they are nearly identical.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

Paul St George
Posts: 3
Joined: Thu May 24, 2018 6:29 pm

Re: PIL show() method

Sat May 26, 2018 1:26 pm

Perhaps I should take a step back? As show() is really just for debugging, is there a better library and method for the display of images?

And thank you! I did not know about GraphicsMagick. It might be better than ImageMagick. If nothing else, I could find much better documentation for GraphicsMagick.

hippy
Posts: 3409
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: PIL show() method

Sat May 26, 2018 6:37 pm

Paul St George wrote:
Sat May 26, 2018 1:26 pm
Perhaps I should take a step back?... is there a better library and method for the display of images?
You could take a look at what pygame offers.

User avatar
scruss
Posts: 1731
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: PIL show() method

Sun May 27, 2018 6:12 pm

Paul St George wrote:
Sat May 26, 2018 1:26 pm
…is there a better library and method for the display of images?
Depends what you want. show() dumps the image to a temporary PNM file and then just calls display to show it. It'll likely show anything you could possibly want from it, but might be of limited use if you're looking at (say) terrain images, which all come out as faint variations of grey.

You could display directly in pygame (as mentioned) or in Tkinter if you want the image displayed in a window you control. Display has the great advantage of allowing further modification and saving in many formats.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

Paul St George
Posts: 3
Joined: Thu May 24, 2018 6:29 pm

Re: PIL show() method

Sun May 27, 2018 7:02 pm

Thank you all. We started with Hobson’s choice and now I am like Buridan’s donkey, midway between two choices: pygame or Tkinter. I will try both.

Return to “Python”

Who is online

Users browsing this forum: No registered users and 13 guests