mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-16 01:57:13 +00:00
now including direction of vview of the photo
This commit is contained in:
@@ -106,7 +106,58 @@ def reorient_image(img, exif_dict):
|
||||
elif orientation == 8:
|
||||
img = img.rotate(90, expand=True)
|
||||
return img
|
||||
|
||||
def dms2dd(degrees, minutes, seconds, direction):
|
||||
dd = float(degrees) + float(minutes)/60 + float(seconds)/(60*60);
|
||||
if direction == 'S' or direction == 'W':
|
||||
dd *= -1
|
||||
return dd;
|
||||
|
||||
def extract_gps(dict):
|
||||
"""Produce a set of annotations to add to an image description
|
||||
"""
|
||||
def rational(tup):
|
||||
nom, denom = tup
|
||||
return nom/denom
|
||||
|
||||
def extract(gpsifd):
|
||||
print(piexif.GPSIFD)
|
||||
n, d = dict[getattr(piexif.GPSIFD, gpsifd)]
|
||||
return n/d
|
||||
|
||||
|
||||
|
||||
compass_points = ["N", "NE", "E", "SE", "S", "SW", "W", "NW", "N"]
|
||||
bearing = extract("GPSImgDirection")
|
||||
compass_lookup = round(bearing / 45)
|
||||
nsew = compass_points[compass_lookup]
|
||||
if dict[piexif.GPSIFD.GPSImgDirectionRef] == b"M":
|
||||
ref = "Magnetic"
|
||||
elif dict[piexif.GPSIFD.GPSImgDirectionRef] == b"T":
|
||||
ref = "True"
|
||||
direction = f"Direction of view: {nsew:2} ({bearing:.0f}°{ref})"
|
||||
|
||||
|
||||
print(f"{dict[piexif.GPSIFD.GPSVersionID]=}")
|
||||
|
||||
|
||||
|
||||
alt = extract("GPSAltitude")
|
||||
altitude = f"{alt:.0f}m above sea-level"
|
||||
ds = dict[piexif.GPSIFD.GPSDateStamp]
|
||||
hf, mf, sf = dict[piexif.GPSIFD.GPSTimeStamp]
|
||||
h = rational(hf)
|
||||
m = rational(mf)
|
||||
s = rational(sf)
|
||||
|
||||
timestamp_utc = f"{ds.decode()} {h:02.0f}:{m:02.0f}:{s:02.0f} +00:00 UTC"
|
||||
|
||||
print(direction)
|
||||
print(altitude)
|
||||
print(timestamp_utc)
|
||||
# location = dms2dd()
|
||||
|
||||
return f"{direction}<br />{altitude}</br />{timestamp_utc}<br />"
|
||||
|
||||
@login_required_if_public
|
||||
def new_image_form(request, path):
|
||||
@@ -148,8 +199,11 @@ def new_image_form(request, path):
|
||||
i_original = i
|
||||
if "exif" in i.info:
|
||||
exif_dict = piexif.load(i.info["exif"])
|
||||
gps_data = exif_dict['GPS']
|
||||
# print(f"new_image_form() EXIF loaded from {f.name}\n {gps_data=}")
|
||||
if "GPS" in exif_dict:
|
||||
gps_data = exif_dict['GPS']
|
||||
print(f"new_image_form() EXIF loaded from {f.name}\n {gps_data=}")
|
||||
gps_annotations = extract_gps(gps_data)
|
||||
descrip += gps_annotations
|
||||
i = reorient_image(i, exif_dict)
|
||||
exif_dict['Exif'][41729] = b'1' # I am not sure this should be binary..
|
||||
# can crash here with bad exif data
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<div class="centre"><img alt="" src="{{ filepath }}" />
|
||||
</div>
|
||||
|
||||
<p>{{ description }}</p>
|
||||
<p>{{ description|safe }}</p>
|
||||
|
||||
{% if photographer %}
|
||||
<p class="caption">Photo © {{ photographer }}{% if year %}, {{ year }}{% endif %}</p>
|
||||
|
||||
Reference in New Issue
Block a user