Last active
December 26, 2017 01:17
-
-
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 ⭐️
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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