Why does PIL fail to display images with error "No images found in "file:///tmp/tmp.....PNG"

Viewed 780

I'm trying to use PIL to display JPEG images. The code I'm using is:

    import numpy as np
    from PIL import Image

    for curr_im in f.readlines(): # Loop through file with names of image files
        print(curr_im) #print name of image file

        with Image.open(os.path.join('./sample/images/',curr_im)) as z:
            z.show() # Show image

            zz=np.asarray(z)
            print(zz.max(), zz.min(), zz.dtype, zz.shape) # Verify something has been read
            x=input("Pause") 
            

The output I see generated is:

val_0.JPEG
255 0 uint8 (64, 64, 3)
Pause 
val_1.JPEG
255 0 uint8 (64, 64, 3)
Pause

So, I can see I'm reading files that exist and that something very image like is being read.

But the window that opens to display the image is blank and has the message "No images found in "file:///tmp/tmp.....PNG". Why does this happen??? (Note: the "....." is in place of a seemingly random string of letters & numbers.

I'm using Python 3.7.6 and PIL 7.0.0.

Note: Every once in a while, the image does display correctly, but with no rhyme or reason I can detect.

0 Answers
Related