1

I've been trying to show a image with PIL but I don't know why the image viewer keeps giving me this:"Windows photo viewer can't open this picture because either the picture is deleted,or it's in a location that isn't available. I've checked the pic is on my desktop and doesn't have any problem. Here is my code:

from PIL import Image
img = Image.open('photo_2016-08-04_22-38-11.jpg')
img.show()

Could any one help me with this?

MrPrg
  • 13
  • 7
  • is image present in the current working directory of the python file? else provide full path of the image? Try Image.open('c:\\users\\\\Desktop\\photo_2016-08-04_22-38-11.jpg') – be_good_do_good Aug 10 '16 at 18:43

1 Answers1

0

Try this little snippet:

from PIL import Image
import os

home_path = os.path.expanduser('~')
filename = os.path.join(home_path,'Desktop','photo_2016-08-04_22-38-11.jpg')

if os.path.exists(filename):
    print "Opening filename {0}".format(filename)
    img = Image.open(filename)
    img.show()
else:
    print "Filename {0} doesn't exist".format(filename)
BPL
  • 9,632
  • 9
  • 59
  • 117
  • again I get the same message – MrPrg Aug 10 '16 at 19:11
  • @MrPrg Ok, I've edited my answer to give you more insights, if that picture doesn't exist the script should notify you. I've tried over here both cases, when the picture exists and when it doesn't, it works ok in both cases. – BPL Aug 10 '16 at 19:14
  • @MrPrg There isn't anything wrong with the provided code... so let's try another thing, what happens if you open that jpg directly with the Windows Photo Viewer directly? If you can't... can you open it with another image editor? – BPL Aug 10 '16 at 19:36
  • yeah it displays the image when I open it with photo viewer directly. – MrPrg Aug 10 '16 at 19:47
  • oh,I could fix it by changing my default photo viewer,I changed it to "paint" and it worked.I guess my windows photo viewer has a problem. – MrPrg Aug 10 '16 at 20:01
  • 1
    @MrPrg: There's a bug in Windows Live Photo Gallery 2011 related to this issue. See the comments under [this answer](http://stackoverflow.com/a/12571366/355230) for a link that may fix it. – martineau Aug 10 '16 at 20:14