update app/photo_routes/scripts/get_exif_data.py to account

for new exif data type of IFDRational, instead of tuple for
some exif attributes
This commit is contained in:
Trent Palmer 2025-02-10 16:27:51 -08:00
parent 7997202d77
commit f0d0d1479c

View File

@ -41,15 +41,19 @@ def get_exif(img_raw, exif_data):
date_format, date_format,
) )
if v == "FNumber": if v == "FNumber":
exif_data['fnumber'] = round( if type(exifdata[k]) == tuple:
exifdata[k][0] / exifdata[k][1], x, y = exifdata[k][0], exifdata[k][1]
1, else:
) x = exifdata[k].numerator
y = exifdata[k].denominator
exif_data['fnumber'] = round(x / y, 1)
if v == "DigitalZoomRatio": if v == "DigitalZoomRatio":
exif_data['DigitalZoomRatio'] = round( if type(exifdata[k]) == tuple:
exifdata[k][0] / exifdata[k][1], x, y = exifdata[k][0], exifdata[k][1]
2, else:
) x = exifdata[k].numerator
y = exifdata[k].denominator
exif_data['DigitalZoomRatio'] = round(x / y, 2)
if v == "TimeZoneOffset": if v == "TimeZoneOffset":
exif_data['TimeZoneOffset'] = exifdata[k] exif_data['TimeZoneOffset'] = exifdata[k]
if v == "GPSInfo": if v == "GPSInfo":
@ -62,10 +66,13 @@ def get_exif(img_raw, exif_data):
"big", "big",
) )
if i == 'GPSAltitude': if i == 'GPSAltitude':
gpsinfo['GPSAltitude'] = round( if type(exifdata[k][h]) == tuple:
exifdata[k][h][0] / exifdata[k][h][1], x = exifdata[k][h][0]
3, y = exifdata[k][h][1]
) else:
x = exifdata[k][h].numerator
y = exifdata[k][h].denominator
gpsinfo['GPSAltitude'] = round(x / y, 3)
if i == 'GPSLatitudeRef': if i == 'GPSLatitudeRef':
gpsinfo['GPSLatitudeRef'] = exifdata[k][h] gpsinfo['GPSLatitudeRef'] = exifdata[k][h]
if i == 'GPSLatitude': if i == 'GPSLatitude':
@ -100,10 +107,20 @@ def update_gpsinfo(gpsinfo, exif_data):
def calc_coordinate(x): def calc_coordinate(x):
degrees = x[0][0] / x[0][1] if type(x[0]) == tuple:
minutes = x[1][0] / x[1][1] degrees = x[0][0] / x[0][1]
seconds = x[2][0] / x[2][1] else:
return round(degrees + minutes / 60 + seconds / 3600, 5) degrees = x[0].numerator / x[0].denominator
if type(x[1]) == tuple:
minutes = x[1][0] / x[1][1]
else:
minutes = x[1].numerator / x[1].denominator
if type(x[2]) == tuple:
seconds = x[2][0] / x[2][1]
else:
seconds = x[2].numerator / x[2].denominator
result = round(degrees + minutes / 60 + seconds / 3600, 5)
return result
def get_dimensions_and_format(photo, exif_data): def get_dimensions_and_format(photo, exif_data):