Last active
August 29, 2015 14:01
-
-
Save ffoxin/664b40e433511cad6b6a to your computer and use it in GitHub Desktop.
Fix EXIF info of photos taken by Pantech P9070 (Burst) camera
This file contains hidden or 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
__author__ = 'Vital Kolas' | |
__version__ = '0.1.1' | |
__date__ = '2014-05-16' | |
import os | |
import pexif | |
target = 'G:\DCIM\Camera' | |
out = 'd:\Temp\Camera' | |
def get_date(file_name): | |
return '{year}:{month}:{day} {hour}:{minute}:{second}'.format( | |
year=file_name[4:8], | |
month=file_name[8:10], | |
day=file_name[10:12], | |
hour=file_name[13:15], | |
minute=file_name[15:17], | |
second=file_name[17:19] | |
) | |
if __name__ == '__main__': | |
for f in os.listdir(target): | |
full_f = os.path.join(target, f) | |
if os.path.isfile(full_f) and f.startswith('IMG_') and f.endswith('.jpg'): | |
try: | |
img = pexif.JpegFile.fromFile(full_f) | |
if img.exif.primary.ExtendedEXIF.DateTimeOriginal[:4] == '2002': | |
real_date = get_date(f) | |
print('{}: {} -> {}'.format( | |
f, | |
img.exif.primary.ExtendedEXIF.DateTimeOriginal, | |
real_date | |
)) | |
img.exif.primary.ExtendedEXIF.DateTimeOriginal = real_date | |
img.exif.primary.ExtendedEXIF.DateTimeDigitized = real_date | |
img.writeFile(os.path.join(out, f)) | |
except Exception as e: | |
print('Error processing file: ' + f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment