Python Forum
Pillow _getexif for python 3
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pillow _getexif for python 3
#1
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+
Reply
#2
Just use the size attribute of the image returned by Image.open
image.size
The size is given as a 2-tuple (width, height).
Reply
#3
Hello Yoriz,

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

Larz60+
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Pillow I_Am_Groot 1 2,617 Oct-13-2018, 07:28 AM
Last Post: j.crater
  [split] Python Pillow - Photo Manipulation keegan_010 1 2,941 Oct-11-2018, 09:57 AM
Last Post: Larz60+
  Python Pillow - Photo Manipulation keegan_010 2 2,871 Oct-11-2018, 03:49 AM
Last Post: keegan_010
  Combine images using Pillow and Python GMA 2 12,790 Jun-06-2018, 11:41 AM
Last Post: killerrex

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020