Python Forum
Pillow _getexif for python 3 - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Pillow _getexif for python 3 (/thread-235.html)



Pillow _getexif for python 3 - Larz60+ - Oct-01-2016

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+


RE: Pillow _getexif for python 3 - Yoriz - Oct-01-2016

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


RE: Pillow _getexif for python 3 - Larz60+ - Oct-01-2016

Hello Yoriz,

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

Larz60+