Python Forum

Full Version: Pillow _getexif for python 3
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

When pillow 2.1.0 was released, it included the following:


Quote:(1.1.4b1 released)

+ Added experimental EXIF support for JPEG files.  To extract EXIF
 information from a JPEG file, open the file as usual, and call the
 "_getexif" method.  If successful, this method returns a dictionary
 mapping EXIF TIFF tags to values.  If the file does not contain EXIF
 data, the "_getexif" method returns None.


caveat: (I did underline experimental)

Has anyone had success with this? I have been developing on MS windows 7 pro (unfortunately for me) as of late, and always get 'None' as a reply.

here's a sample:
from PIL import Image


class SizeOfImage:
    def __init__(self, filename=None):
        self.filename = filename

    def get_exif(self):
        ret = {}
        i = Image.open(self.filename)
        info = i._getexif()
        print('info: {}'.format(info))
        return ret

if __name__ == '__main__':
    szimg = SizeOfImage(filename='images/generalmotors.jpg')
    szimg.get_exif()
The image opens fine, but the result I get from above code is always None. I've tried it with several images with the same results.
Is there another way to do this? All I really want are the image dimensions

Larz60+
Just use the size attribute of the image returned by Image.open
image.size
The size is given as a 2-tuple (width, height).
Hello Yoriz,

Thanks, That's too easy.
Never looking for what's in front of me all along - ( ut iocularis ).

Larz60+