Made optional Values optional in Exif class.
This commit is contained in:
parent
f6a54a5855
commit
13555a0505
59
functions.py
59
functions.py
|
@ -107,7 +107,7 @@ class Exif:
|
||||||
Exif-Comment that has been written (incl. radiation)
|
Exif-Comment that has been written (incl. radiation)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self, photo, radiation, latitude, longitude, elevation, dry_run):
|
def __init__(self, photo, dry_run, radiation=False, latitude=False, longitude=False, elevation=False):
|
||||||
self.write_exif = self._write_exif(photo, radiation, latitude,
|
self.write_exif = self._write_exif(photo, radiation, latitude,
|
||||||
longitude, elevation, dry_run)
|
longitude, elevation, dry_run)
|
||||||
|
|
||||||
|
@ -128,36 +128,45 @@ class Exif:
|
||||||
second = round((t1 - minute) * 60, 5)
|
second = round((t1 - minute) * 60, 5)
|
||||||
return (deg, minute, second, loc_value)
|
return (deg, minute, second, loc_value)
|
||||||
|
|
||||||
def _write_exif(self, photo, radiation, latitude, longitude, elevation, dry_run):
|
def _write_exif(self, photo, dry_run, radiation, latitude, longitude, elevation):
|
||||||
|
|
||||||
metadata = pyexiv2.ImageMetadata(photo)
|
metadata = pyexiv2.ImageMetadata(photo)
|
||||||
metadata.read()
|
metadata.read()
|
||||||
|
|
||||||
latitude_degree = self._to_degree(latitude, ["S", "N"])
|
if latitude or longitude:
|
||||||
longitude_degree = self._to_degree(longitude, ["W", "E"])
|
latitude_degree = self._to_degree(latitude, ["S", "N"])
|
||||||
|
longitude_degree = self._to_degree(longitude, ["W", "E"])
|
||||||
|
|
||||||
# convert decimal coordinates into fractions required for pyexiv2
|
# convert decimal coordinates into fractions required for pyexiv2
|
||||||
exiv2_latitude = (Fraction(latitude_degree[0] * 60 + latitude_degree[1], 60),
|
exiv2_latitude = (Fraction(latitude_degree[0] * 60 + latitude_degree[1], 60),
|
||||||
Fraction(int(round(latitude_degree[2] * 100, 0)), 6000),
|
Fraction(int(round(latitude_degree[2] * 100, 0)), 6000),
|
||||||
Fraction(0, 1))
|
Fraction(0, 1))
|
||||||
exiv2_longitude = (Fraction(longitude_degree[0] * 60 + longitude_degree[1], 60),
|
exiv2_longitude = (Fraction(longitude_degree[0] * 60 + longitude_degree[1], 60),
|
||||||
Fraction(int(round(longitude_degree[2] * 100, 0)), 6000),
|
Fraction(int(round(longitude_degree[2] * 100, 0)), 6000),
|
||||||
Fraction(0, 1))
|
Fraction(0, 1))
|
||||||
|
|
||||||
# Set new UserComment
|
# Exif tags to write
|
||||||
new_comment = 'Radiation ☢ ' + str(radiation) + ' µS/h'
|
metadata['Exif.GPSInfo.GPSLatitude'] = exiv2_latitude
|
||||||
|
metadata['Exif.GPSInfo.GPSLatitudeRef'] = latitude_degree[3]
|
||||||
# Exif tags to write
|
metadata['Exif.GPSInfo.GPSLongitude'] = exiv2_longitude
|
||||||
metadata['Exif.GPSInfo.GPSLatitude'] = exiv2_latitude
|
metadata['Exif.GPSInfo.GPSLongitudeRef'] = longitude_degree[3]
|
||||||
metadata['Exif.GPSInfo.GPSLatitudeRef'] = latitude_degree[3]
|
metadata['Exif.Image.GPSTag'] = 654
|
||||||
metadata['Exif.GPSInfo.GPSLongitude'] = exiv2_longitude
|
metadata['Exif.GPSInfo.GPSMapDatum'] = "WGS-84"
|
||||||
metadata['Exif.GPSInfo.GPSLongitudeRef'] = longitude_degree[3]
|
metadata['Exif.GPSInfo.GPSVersionID'] = '2 0 0 0'
|
||||||
metadata['Exif.GPSInfo.GPSAltitude'] = Fraction(elevation)
|
|
||||||
metadata['Exif.GPSInfo.GPSAltitudeRef'] = '0'
|
if not elevation:
|
||||||
metadata['Exif.Image.GPSTag'] = 654
|
metadata['Exif.GPSInfo.GPSAltitude'] = Fraction(elevation)
|
||||||
metadata['Exif.GPSInfo.GPSMapDatum'] = "WGS-84"
|
metadata['Exif.GPSInfo.GPSAltitudeRef'] = '0'
|
||||||
metadata['Exif.GPSInfo.GPSVersionID'] = '2 0 0 0'
|
else:
|
||||||
metadata['Exif.Photo.UserComment'] = new_comment
|
latitude_degree = None
|
||||||
|
longitude_degree = None
|
||||||
|
|
||||||
|
if radiation:
|
||||||
|
# Set new UserComment
|
||||||
|
new_comment = 'Radiation ☢ ' + str(radiation) + ' µS/h'
|
||||||
|
metadata['Exif.Photo.UserComment'] = new_comment
|
||||||
|
else:
|
||||||
|
new_comment = None
|
||||||
|
|
||||||
# Write Exif tags to file, if not in dry-run mode
|
# Write Exif tags to file, if not in dry-run mode
|
||||||
if dry_run is not True:
|
if dry_run is not True:
|
||||||
|
|
|
@ -90,13 +90,13 @@ for src_photo in args.photos:
|
||||||
print(photo.get_target_photo, photo.get_date)
|
print(photo.get_target_photo, photo.get_date)
|
||||||
|
|
||||||
# Here the matching magic has to happen
|
# Here the matching magic has to happen
|
||||||
latitude = 51.0234024
|
#latitude = 51.0234024
|
||||||
longitude = 7.248347
|
#longitude = 7.248347
|
||||||
radiation = 9001.15
|
radiation = 9001.15
|
||||||
elevation = 56.079345703125
|
#elevation = 56.079345703125
|
||||||
|
|
||||||
# Write exif data
|
# Write exif data
|
||||||
exif_tags = Exif(photo.get_target_photo, radiation, latitude, longitude, elevation, args.dry)
|
exif_tags = Exif(photo=photo.get_target_photo, dry_run=args.dry)
|
||||||
print(exif_tags)
|
print(exif_tags)
|
||||||
|
|
||||||
# Print table header
|
# Print table header
|
||||||
|
|
Loading…
Reference in New Issue