Skip to content

Instantly share code, notes, and snippets.

@kmonsoor
Last active December 26, 2017 01:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmonsoor/1e3263c4b26c4c1674b8b29274d528d8 to your computer and use it in GitHub Desktop.
Save kmonsoor/1e3263c4b26c4c1674b8b29274d528d8 to your computer and use it in GitHub Desktop.
Rename JPG files to `Unique image id` of EXIF data. If you find this useful, as a 👍, give this gist a ⭐️
import os
import glob
import exifread
NAME_LENGTH = 10
jpg_files = glob.glob('*.jpg')
for a_file in jpg_files:
try:
tags = exifread.process_file(open(a_file, 'rb'))
except Exception as e:
print(e)
print("Couldn't open the file, skipping: {}".format(a_file))
continue
uid = str(tags.get('EXIF ImageUniqueID', ''))
if not len(uid):
print("{} --> UniqueID not present in EXIF".format(a_file))
elif len(uid) < 30:
print("{} --> Possibly corrupted EXIF; {}".format(a_file, uid))
else:
new_name = uid[:NAME_LENGTH] + '.jpg'
print("{} --> new name: {}".format(a_file, new_name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment