Python PIL library not working image.thumbnail(size, Image.ANTIALIAS)
Question: I'm trying to debug this script in python from PIL import Image, ImageChops,
ImageOps

I've searched all over the problem seems to be "image.thumbnail(size,
Image.ANTIALIAS)" here. Anyone have any ideas? Thanks

    
    
    image = Image.open(f_in)
    print "got here"
    image.thumbnail(size, Image.ANTIALIAS)
    print "cannot get here"
    image_size = image.size
    if pad:
        thumb = image.crop( (0, 0, size[0], size[1]) )
    
        offset_x = max( (size[0] - image_size[0]) / 2, 0 )
        offset_y = max( (size[1] - image_size[1]) / 2, 0 )
    
        thumb = ImageChops.offset(thumb, offset_x, offset_y)
    
    else:
        thumb = ImageOps.fit(image, size, Image.ANTIALIAS, (0.5, 0.5))
    
    thumb.save(f_out)
    

**EDIT** Thanks for the quick answer Mark. I figured it out.

I had to:

    
    
    pip uninstall PIL
    sudo apt-get install libjpeg8-dev 
    pip install PIL
    

I didn't have libjpeg installed. Not sure why I didn't get an error.


Answer: If the program never gets to the line "cannot get here" then the problem is
that `thumbnail` is throwing an exception. You didn't mention that in the
question though, it should have generated an error.

PIL uses lazy image loading - in the `open` call it might open the file, but
it doesn't actually try to read the whole thing in. If your file is corrupt or
in the wrong format it will fail once you try to do something with the image,
as `thumbnail` is doing.

