Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
metadata['Exif.Photo.DateTimeOriginal'] = timestamp
t = metadata['Exif.Photo.DateTimeOriginal'].value
# subtract offset in s beween gpx time and exif time
t = t - datetime.timedelta(seconds=offset_time)
try:
lat, lon, bearing, elevation = interpolate_lat_lon(points, t)
lat_deg = to_deg(lat, ["S", "N"])
lon_deg = to_deg(lon, ["W", "E"])
# convert decimal coordinates into degrees, minutes and seconds as fractions for EXIF
exiv_lat = (make_fraction(lat_deg[0],1), make_fraction(int(lat_deg[1]),1), make_fraction(int(lat_deg[2]*1000000),1000000))
exiv_lon = (make_fraction(lon_deg[0],1), make_fraction(int(lon_deg[1]),1), make_fraction(int(lon_deg[2]*1000000),1000000))
# convert direction into fraction
exiv_bearing = make_fraction(int(bearing*1000),1000)
# add to exif
metadata["Exif.GPSInfo.GPSLatitude"] = exiv_lat
metadata["Exif.GPSInfo.GPSLatitudeRef"] = lat_deg[3]
metadata["Exif.GPSInfo.GPSLongitude"] = exiv_lon
metadata["Exif.GPSInfo.GPSLongitudeRef"] = lon_deg[3]
metadata["Exif.Image.GPSTag"] = 654
metadata["Exif.GPSInfo.GPSMapDatum"] = "WGS-84"
metadata["Exif.GPSInfo.GPSVersionID"] = '2 0 0 0'
metadata["Exif.GPSInfo.GPSImgDirection"] = exiv_bearing
metadata["Exif.GPSInfo.GPSImgDirectionRef"] = "T"
metadata["Exif.Image.Orientation"] = orientation
if image_description is not None:
if timestamp:
metadata['Exif.Photo.DateTimeOriginal'] = timestamp
t = metadata['Exif.Photo.DateTimeOriginal'].value
# subtract offset in s beween gpx time and exif time
t = t - datetime.timedelta(seconds=offset_time)
try:
lat, lon, bearing, elevation = interpolate_lat_lon(points, t)
lat_deg = to_deg(lat, ["S", "N"])
lon_deg = to_deg(lon, ["W", "E"])
# convert decimal coordinates into degrees, minutes and seconds as fractions for EXIF
exiv_lat = (make_fraction(lat_deg[0],1), make_fraction(int(lat_deg[1]),1), make_fraction(int(lat_deg[2]*1000000),1000000))
exiv_lon = (make_fraction(lon_deg[0],1), make_fraction(int(lon_deg[1]),1), make_fraction(int(lon_deg[2]*1000000),1000000))
# convert direction into fraction
exiv_bearing = make_fraction(int(bearing*1000),1000)
# add to exif
metadata["Exif.GPSInfo.GPSLatitude"] = exiv_lat
metadata["Exif.GPSInfo.GPSLatitudeRef"] = lat_deg[3]
metadata["Exif.GPSInfo.GPSLongitude"] = exiv_lon
metadata["Exif.GPSInfo.GPSLongitudeRef"] = lon_deg[3]
metadata["Exif.Image.GPSTag"] = 654
metadata["Exif.GPSInfo.GPSMapDatum"] = "WGS-84"
metadata["Exif.GPSInfo.GPSVersionID"] = '2 0 0 0'
metadata["Exif.GPSInfo.GPSImgDirection"] = exiv_bearing
metadata["Exif.GPSInfo.GPSImgDirectionRef"] = "T"
metadata["Exif.Image.Orientation"] = orientation
# add to exif
metadata["Exif.GPSInfo.GPSLatitude"] = exiv_lat
metadata["Exif.GPSInfo.GPSLatitudeRef"] = lat_deg[3]
metadata["Exif.GPSInfo.GPSLongitude"] = exiv_lon
metadata["Exif.GPSInfo.GPSLongitudeRef"] = lon_deg[3]
metadata["Exif.Image.GPSTag"] = 654
metadata["Exif.GPSInfo.GPSMapDatum"] = "WGS-84"
metadata["Exif.GPSInfo.GPSVersionID"] = '2 0 0 0'
metadata["Exif.GPSInfo.GPSImgDirection"] = exiv_bearing
metadata["Exif.GPSInfo.GPSImgDirectionRef"] = "T"
metadata["Exif.Image.Orientation"] = orientation
if image_description is not None:
metadata["Exif.Image.ImageDescription"] = image_description
if elevation is not None:
exiv_elevation = make_fraction(int(abs(elevation)*100),100)
metadata["Exif.GPSInfo.GPSAltitude"] = exiv_elevation
metadata["Exif.GPSInfo.GPSAltitudeRef"] = '0' if elevation >= 0 else '1'
metadata.write()
print("Added geodata to: {0} ({1}, {2}, {3}), altitude {4}".format(filename, lat, lon, bearing, elevation))
except ValueError as e:
print("Skipping {0}: {1}".format(filename, e))
# subtract offset in s beween gpx time and exif time
t = t - datetime.timedelta(seconds=offset_time)
try:
lat, lon, bearing, elevation = interpolate_lat_lon(points, t)
lat_deg = to_deg(lat, ["S", "N"])
lon_deg = to_deg(lon, ["W", "E"])
# convert decimal coordinates into degrees, minutes and seconds as fractions for EXIF
exiv_lat = (make_fraction(lat_deg[0],1), make_fraction(int(lat_deg[1]),1), make_fraction(int(lat_deg[2]*1000000),1000000))
exiv_lon = (make_fraction(lon_deg[0],1), make_fraction(int(lon_deg[1]),1), make_fraction(int(lon_deg[2]*1000000),1000000))
# convert direction into fraction
exiv_bearing = make_fraction(int(bearing*1000),1000)
# add to exif
metadata["Exif.GPSInfo.GPSLatitude"] = exiv_lat
metadata["Exif.GPSInfo.GPSLatitudeRef"] = lat_deg[3]
metadata["Exif.GPSInfo.GPSLongitude"] = exiv_lon
metadata["Exif.GPSInfo.GPSLongitudeRef"] = lon_deg[3]
metadata["Exif.Image.GPSTag"] = 654
metadata["Exif.GPSInfo.GPSMapDatum"] = "WGS-84"
metadata["Exif.GPSInfo.GPSVersionID"] = '2 0 0 0'
metadata["Exif.GPSInfo.GPSImgDirection"] = exiv_bearing
metadata["Exif.GPSInfo.GPSImgDirectionRef"] = "T"
metadata["Exif.Image.Orientation"] = orientation
if image_description is not None:
metadata["Exif.Image.ImageDescription"] = image_description
if elevation is not None:
'''
Given lat, lon, bearing, elevation, write to EXIF
'''
# TODO: use this within add_exif_using_timestamp
if updated_filename is not None:
shutil.copy2(filename, updated_filename)
filename = updated_filename
metadata = pyexiv2.ImageMetadata(filename)
metadata.read()
lat_deg = to_deg(lat, ["S", "N"])
lon_deg = to_deg(lon, ["W", "E"])
# convert decimal coordinates into degrees, minutes and seconds as fractions for EXIF
exiv_lat = (make_fraction(lat_deg[0],1), make_fraction(int(lat_deg[1]),1), make_fraction(int(lat_deg[2]*1000000),1000000))
exiv_lon = (make_fraction(lon_deg[0],1), make_fraction(int(lon_deg[1]),1), make_fraction(int(lon_deg[2]*1000000),1000000))
# convert direction into fraction
exiv_bearing = make_fraction(int(bearing*100),100)
# add to exif
metadata["Exif.GPSInfo.GPSLatitude"] = exiv_lat
metadata["Exif.GPSInfo.GPSLatitudeRef"] = lat_deg[3]
metadata["Exif.GPSInfo.GPSLongitude"] = exiv_lon
metadata["Exif.GPSInfo.GPSLongitudeRef"] = lon_deg[3]
metadata["Exif.Image.GPSTag"] = 654
metadata["Exif.GPSInfo.GPSMapDatum"] = "WGS-84"
metadata["Exif.GPSInfo.GPSVersionID"] = '2 0 0 0'
metadata["Exif.GPSInfo.GPSImgDirection"] = exiv_bearing
metadata["Exif.GPSInfo.GPSImgDirectionRef"] = "T"
if remove_image_description: metadata["Exif.Image.ImageDescription"] = []
# TODO: use this within add_exif_using_timestamp
if updated_filename is not None:
shutil.copy2(filename, updated_filename)
filename = updated_filename
metadata = pyexiv2.ImageMetadata(filename)
metadata.read()
lat_deg = to_deg(lat, ["S", "N"])
lon_deg = to_deg(lon, ["W", "E"])
# convert decimal coordinates into degrees, minutes and seconds as fractions for EXIF
exiv_lat = (make_fraction(lat_deg[0],1), make_fraction(int(lat_deg[1]),1), make_fraction(int(lat_deg[2]*1000000),1000000))
exiv_lon = (make_fraction(lon_deg[0],1), make_fraction(int(lon_deg[1]),1), make_fraction(int(lon_deg[2]*1000000),1000000))
# convert direction into fraction
exiv_bearing = make_fraction(int(bearing*100),100)
# add to exif
metadata["Exif.GPSInfo.GPSLatitude"] = exiv_lat
metadata["Exif.GPSInfo.GPSLatitudeRef"] = lat_deg[3]
metadata["Exif.GPSInfo.GPSLongitude"] = exiv_lon
metadata["Exif.GPSInfo.GPSLongitudeRef"] = lon_deg[3]
metadata["Exif.Image.GPSTag"] = 654
metadata["Exif.GPSInfo.GPSMapDatum"] = "WGS-84"
metadata["Exif.GPSInfo.GPSVersionID"] = '2 0 0 0'
metadata["Exif.GPSInfo.GPSImgDirection"] = exiv_bearing
metadata["Exif.GPSInfo.GPSImgDirectionRef"] = "T"
if remove_image_description: metadata["Exif.Image.ImageDescription"] = []
if elevation is not None:
exiv_elevation = make_fraction(int(abs(elevation)*100),100)
metadata["Exif.GPSInfo.GPSAltitude"] = exiv_elevation