[Image-SIG] PIL bug

Morris, Chris cmorris at arete.com
Wed Nov 16 22:03:45 CET 2011

The following code:

    from PIL import Image
    im = Image.open("img.bmp")

brings up the default Windows 7 Image Viewer. The image viewer does not display the image requested, but instead displays "windows photo viewer can't open this picture because either the picture is deleted, or it's in a location that isn't available".

This site: http://www.velocityreviews.com/forums/t707158-python-pil-and-vista-windows-7-show-not-working.html has an explanation for this behavior.
What actually happens is that the Windows code relies on the fact that the default image viewer on Windows XP was able to work at blocking mode - this means that the command will wait until the image window will be closed. Because of that behaviour, they constructed a command line which deletes a file right after the image has been shown.

Windows Vista doesn't work the same way, it immediately returns once the command has been executed, so what happens now is that the temporary file gets immediately deleted by the command line, and the image viewer doesn't have enough time to load the image before it is being deleted.

Here is a quick workaround:

Edit C:\Python26\lib\site-packages\PIL\ImageShow.py, and around line 99, replace with the following line:

return "start /wait %s && PING -n 5 > NUL && del /f %s" % (file, file)

I would like to report this behavior as a bug.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/image-sig/attachments/20111116/a0d0c25c/attachment-0001.html>

More information about the Image-SIG mailing list