matts0613

exifInfo.py

May 19th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. #requirement - pip3 install pillow
  2. #Usage: python3 exif.py
  3. #simple script that prints exif information for a user
  4. #prompted image name in the same directory as this script
  5.  
  6. from PIL import Image
  7. from PIL.ExifTags import TAGS
  8.  
  9. #prompt user for name of image
  10. imagename = input("Enter name of the image: ")
  11.  
  12. # read the image data using PIL
  13. image = Image.open(imagename)
  14.  
  15. # extract EXIF data
  16. exifdata = image.getexif()
  17.  
  18. # iterating over all EXIF data fields
  19. for tag_id in exifdata:
  20.     # get the tag name, instead of human unreadable tag id
  21.     tag = TAGS.get(tag_id, tag_id)
  22.     data = exifdata.get(tag_id)
  23.     # decode bytes
  24.     if isinstance(data, bytes):
  25.         data = data.decode()
  26.     print(f"{tag:25}: {data}")
Add Comment
Please, Sign In to add comment