Created
December 11, 2016 21:29
-
-
Save lisajamhoury/6826bdfd987a835f2f9145cdcba201c6 to your computer and use it in GitHub Desktop.
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 piexif | |
import exifread | |
import gpsphoto | |
import os | |
import pprint | |
import json | |
import PIL | |
from PIL import Image | |
cwd = os.getcwd() #get current path as string | |
images_data = [] | |
images_directory = os.path.join(cwd, '../images') #os.path.join allows this to work on windows as well for \ | |
for filename in os.listdir(images_directory): | |
image_data = { | |
"filename": filename | |
} | |
image_path = os.path.join(images_directory, filename) | |
resizeImg(image_path) | |
file = open(image_path, 'rb') | |
tags = exifread.process_file(file, details=False) | |
# import pdb; pdb.set_trace() | |
# pprint.pprint(tags) | |
# print image_path | |
data = gpsphoto.getGPSData(image_path) | |
# pprint.pprint(data) | |
if 'Latitude' in data and 'Longitude' in data: | |
image_data['lat'] = data['Latitude'] | |
image_data['long'] = data['Longitude'] | |
image_data['alt'] = data['Altitude'] | |
images_data.append(image_data) | |
# exix_dict = piexif.load(image_path) | |
# print exix_dict | |
pprint.pprint(images_data) | |
with open('exif.json', 'w') as outfile: | |
json.dump(images_data, outfile); | |
def resizeImg(filename): | |
basewidth = 300 | |
img = Image.open(filename) | |
wpercent = (basewidth/float(img.size[0])) | |
hsize = int((float(img.size[1])*float(wpercent))) | |
img = img.resize((basewidth,hsize), PIL.Image.ANTIALIAS) | |
newImgName = os.path.join(images_directory, '/resized', '/rs_', filename) | |
img.save(newImgName) | |
# def getcords(d, m, s, ind): | |
# # Calculate the total number of seconds, | |
# # 43'41" = (43*60 + 41) = 2621 seconds. | |
# sec = float((m * 60) + s) | |
# # The fractional part is total number of | |
# # seconds divided by 3600. 2621 / 3600 = ~0.728056 | |
# frac = float(sec / 3600) | |
# # Add fractional degrees to whole degrees | |
# # to produce the final result: 87 + 0.728056 = 87.728056 | |
# deg = float(d + frac) | |
# # If it is a West or S longitude coordinate, negate the result. | |
# if ind == 'W': | |
# deg = deg * -1 | |
# if ind == 'S': | |
# deg = deg * -1 | |
# return float(deg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment