robertvari

pythonSuli

Nov 18th, 2018
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. # -*- coding:Utf-8 -*-
  2. import os, shutil
  3. from PIL import Image, ExifTags
  4. from datetime import datetime
  5.  
  6. folder = u"E:/Photos/Roma hetvege/"
  7. destFolder = u"E:/Photos/tmp/"
  8.  
  9. # get all .jpg files in folder
  10. files = [folder + i for i in os.listdir(folder) if i.lower().endswith(".jpg")]
  11.  
  12.  
  13. for i in files:
  14.     # get date from file
  15.     timestamp = os.path.getmtime(i)
  16.     date = datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d')
  17.  
  18.     # load photo into Image module
  19.     img = Image.open(i)
  20.  
  21.     # get exif data
  22.     exifData = img._getexif()
  23.  
  24.     # if exif data and type is dictionary
  25.     if exifData and type(exifData) == dict:
  26.  
  27.         # iterate on dictionary
  28.         for key, value in exifData.items():
  29.  
  30.             # check if tag in ExifTags
  31.             if key in ExifTags.TAGS:
  32.  
  33.                 # we need only ISO value
  34.                 if ExifTags.TAGS[key] == "ISOSpeedRatings":
  35.  
  36.                     # create folders with ISO value
  37.                     if not os.path.exists(destFolder + str(value)):
  38.                         os.mkdir(destFolder + str(value))
  39.  
  40.                     # copy files
  41.                     sourceFileName = os.path.basename(i)
  42.                     shutil.copy2(i, destFolder + str(value) + "/" + sourceFileName)
Add Comment
Please, Sign In to add comment