diff options
author | Philip Sargent <philip.sargent@gmail.com> | 2025-02-19 23:13:13 +0200 |
---|---|---|
committer | Philip Sargent <philip.sargent@gmail.com> | 2025-02-19 23:13:13 +0200 |
commit | 6586c00a379b87d7d38b27839b099fa17f3b4502 (patch) | |
tree | 177c4efbb83d95d0a91b795434d03858513c54a0 /core/views | |
parent | 0ab0750511e78bea0431f34c8d931332fbcdf0a2 (diff) | |
download | troggle-6586c00a379b87d7d38b27839b099fa17f3b4502.tar.gz troggle-6586c00a379b87d7d38b27839b099fa17f3b4502.tar.bz2 troggle-6586c00a379b87d7d38b27839b099fa17f3b4502.zip |
now outputs lat+lon onto /l/*.html page for a photo with GPS exif
Diffstat (limited to 'core/views')
-rw-r--r-- | core/views/editor_helpers.py | 67 |
1 files changed, 51 insertions, 16 deletions
diff --git a/core/views/editor_helpers.py b/core/views/editor_helpers.py index 59f4cd1..e0838b6 100644 --- a/core/views/editor_helpers.py +++ b/core/views/editor_helpers.py @@ -126,7 +126,7 @@ def extract_gps(dict): def is_present(gpsifd): item = getattr(piexif.GPSIFD, gpsifd) if item in dict: - print(f" {gpsifd} = {item}") + print(f" {gpsifd} = id '{item}'") return dict[item] return None @@ -139,6 +139,13 @@ def extract_gps(dict): def rational(tup): nom, denom = tup return nom/denom + + def rationalise(item): + df, mf, sf = item + d = rational(df) + m = rational(mf) + s = rational(sf) + return (d, m, s) compass_points = ["N", "NE", "E", "SE", "S", "SW", "W", "NW", "N"] if bearing := extract("GPSImgDirection"): @@ -168,26 +175,54 @@ def extract_gps(dict): ds = ds.decode() else: ds = "" - + if item := is_present("GPSTimeStamp"): - hf, mf, sf = item - h = rational(hf) - m = rational(mf) - s = rational(sf) + h, m, s = rationalise(item) timestamp_utc = f"{ds} {h:02.0f}:{m:02.0f}:{s:02.0f} +00:00 UTC" else: timestamp_utc = f"{ds}" - - + + print(f"attempting latitude") + if ref := is_present("GPSLatitudeRef"): + latref = ref.decode() + else: + latref = "" + + if item := is_present("GPSLatitude"): + d, m, s = rationalise(item) + latitude = f"{d:02.0f}:{m:02.0f}:{s:02.0f} {latref}" + print(f"{latitude=}") + latitude = dms2dd(d, m, s, latref) + print(f"{latitude=}") + else: + print("failed to find latitude") + + print(f"attempting logitude") + if ref := is_present("GPSLongitudeRef"): + lonref = ref.decode() + else: + lonref = "" + + if item := is_present("GPSLongitude"): + d, m, s = rationalise(item) + longitude = f"{d:02.0f}:{m:02.0f}:{s:02.0f} {lonref}" + print(f"{longitude=}") + longitude = dms2dd(d, m, s, lonref) + print(f"{longitude=}") + else: + print("failed to find latitude") + + location = f"{latitude:08.5f} {latref}, {longitude:09.5f} {lonref}" print(direction) print(altitude) print(timestamp_utc) # location = dms2dd() # to do... + print(location) - return f"{direction}<br />{altitude}</br />{timestamp_utc}<br />" + return f"{direction}<br />{location}<br />{altitude}</br />{timestamp_utc}<br />" def fix_dump_bugs(exif_dict): - """piexif has a bug, this gets around it. + """piexif has several bugs, this gets around it. The Exif standard leaves some instance types "undefined". Great :-( see https://github.com/hMatoba/Piexif/issues/83 @@ -204,12 +239,12 @@ def fix_dump_bugs(exif_dict): if isinstance(cc, tuple): print(f"PIEXIF BUG workaround: 37121 {cc} is {type(cc)}") exif_dict['Exif'][37121] = ",".join([str(v) for v in cc]).encode("ASCII") - if 37380 in exif_dict['Exif']: - # exposure bias - cc = exif_dict['Exif'][37380] - if isinstance(cc, tuple): - print(f"PIEXIF BUG workaround: 37380 {cc} is {type(cc)}") - exif_dict['Exif'][37380] = (0, 1) + # if 37380 in exif_dict['Exif']: + # # exposure bias + # cc = exif_dict['Exif'][37380] + # if isinstance(cc, tuple): + # print(f"PIEXIF BUG workaround: 37380 exposure bias: {cc} is {type(cc)}") + # exif_dict['Exif'][37380] = (0, 1) if 50728 in exif_dict['Exif']: cc = exif_dict['Exif'][50728] |