From: Esmail on
Hello all.

I am using the PIL 1.1.6 and Python 2.6.x under XP without any
problems. However, I can't display any images under Vista
or Windows 7. I could understand Windows 7 as it's relatively
new, but Vista has been around for a bit.

Sample code:

import Image

im = Image.open('c://mypic.jpg')
im.show()


this will work fine under XP, but under Windows 7 and Vista
the default image viewer will come up with some error message
that the image can't be found.

I tried with an external image view program and tried to supply
it via the command parameter to show - but that too didn't work.

Definition: im.show(self, title=None, command=None)

Any suggestions/help/workarounds? If you can get this to work
with Vista or Windows 7 I'd love to hear from you.

Thanks!
Esmail

From: Esmail on
>
>   im = Image.open('c://mypic.jpg')

sorry, slip of the finger, there's only one forward slash
or you can use two backward slashes.

The problem isn't with opening it (I know it opens fine
since I can get its size attribute via im.size) - the show()
is the problem.

Esmail
From: Lie Ryan on
On 12/1/2009 5:04 AM, Esmail wrote:
>>
>> im = Image.open('c://mypic.jpg')
>
> sorry, slip of the finger, there's only one forward slash
> or you can use two backward slashes.
>
> The problem isn't with opening it (I know it opens fine
> since I can get its size attribute via im.size) - the show()
> is the problem.


What's your default image viewer? im.show is intended to be for
debugging purpose and may always guaranteed to work if your image viewer
doesn't support receiving the file through <I don't know how PIL passes
the image to the program>.
From: Esmail on
On Nov 30, 3:08 pm, Lie Ryan <lie.1...(a)gmail.com> wrote:
>
> What's your default image viewer? im.show is intended to be for
> debugging purpose and may always guaranteed to work if your image viewer
> doesn't support receiving the file through <I don't know how PIL passes
> the image to the program>.


It's whatever the default windows viewer is :-) .. so if I double-
click on
the image in the filemanager it fires it up and shows it. This works
in XP and Windows 7 and Vista (ie double clicking on the image and
having it display).

I dug around in the docs and found a named parameter that I can set
when I
call show.

Definition: im.show(self, title=None, command=None)

I installed irfanview and specified it/its path in the parameter,
but that didn't work either. It's really quite puzzling in the
case of Vista since that's been around for quite a few years now.


Esmail
From: David Bolen on
Esmail <ebonak(a)gmail.com> writes:

> I dug around in the docs and found a named parameter that I can set
> when I
> call show.
>
> Definition: im.show(self, title=None, command=None)
>
> I installed irfanview and specified it/its path in the parameter,
> but that didn't work either. It's really quite puzzling in the
> case of Vista since that's been around for quite a few years now.

But I thought everyone was sticking their fingers in their ears and
humming to try to forget Vista had been released, particularly now
that Windows 7 is out :-)

Perhaps there's an issue with the temporary file location. I don't
have a Vista system to test on, but the show() operation writes the
image to a temporary file as returned by tempfile.mktemp(), and then
passes the name on to the external viewer. The viewing command is
handed to os.system() with the filename embedded without any special
quoting. So if, for example, the temporary location has spaces or
"interesting" characters, it probably won't get parsed properly.

One easy debugging step is probably to add a print just before the
os.system() call that views the image (bottom of _showxv function in
Image.py in my copy of 1.1.6). That way at least you'll know the
exact command being used.

If that's the issue, there are various ways around it. You could
patch PIL itself (same function) to quote the filename when it is
constructing the command. Alternatively, the tempfile module has a
tempdir global you could set to some other temporary directory before
using the show() function (or any other code using tempfile).

-- David