The PIL show() method looks for the default viewer. How do I change this to a different viewer (of my choice)?

boB Stepp robertvstepp at gmail.com
Fri May 25 19:02:16 EDT 2018


On Fri, May 25, 2018 at 6:04 AM, Paul St George <email at paulstgeorge.com> wrote:
> I am using the Python Imaging Library (PIL), Python 2 and Raspberry Pi 3 B+
>
> My code is simply:
>
>     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)?

In the PIL docs for show() at
https://pillow.readthedocs.io/en/5.1.x/reference/Image.html#PIL.Image.Image.show
it says:

<quote>
Image.show(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.

On macOS, this method saves the image to a temporary BMP file, and
opens it with the native Preview application.

On Windows, it saves the image to a temporary BMP file, and uses the
standard BMP display utility to show it (usually Paint).

Parameters:

title – Optional title to use for the image window, where possible.
command – command used to show the image
</quote>

I have not had occasion to use PIL, but perhaps this command parameter
can be used to do what you want?  If not then perhaps you can write
your own function to load your image into your favorite image viewer.


-- 
boB



More information about the Python-list mailing list