mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2026-02-08 13:18:15 +00:00
bugs
This commit is contained in:
@@ -25,6 +25,7 @@ from troggle.core.utils import (
|
|||||||
WriteAndCommitError,
|
WriteAndCommitError,
|
||||||
current_expo,
|
current_expo,
|
||||||
get_editor,
|
get_editor,
|
||||||
|
git_string,
|
||||||
write_and_commit,
|
write_and_commit,
|
||||||
is_identified_user,
|
is_identified_user,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -186,17 +186,49 @@ def extract_gps(dict):
|
|||||||
|
|
||||||
return f"{direction}<br />{altitude}</br />{timestamp_utc}<br />"
|
return f"{direction}<br />{altitude}</br />{timestamp_utc}<br />"
|
||||||
|
|
||||||
|
def fix_dump_bugs(exif_dict):
|
||||||
|
"""piexif has a bug, this gets around it.
|
||||||
|
The Exif standard leaves some instance types "undefined". Great :-(
|
||||||
|
|
||||||
|
see https://github.com/hMatoba/Piexif/issues/83
|
||||||
|
see EXIF standard https://www.cipa.jp/std/documents/e/DC-008-2012_E.pdf
|
||||||
|
"""
|
||||||
|
if 41729 in exif_dict['Exif'] and isinstance(exif_dict['Exif'][41729], int):
|
||||||
|
# SceneType = 1 for a directly photogrpahed image
|
||||||
|
cc = exif_dict['Exif'][41729]
|
||||||
|
print(f"PIEXIF BUG workaround: 41729 {cc} is {type(cc)}")
|
||||||
|
exif_dict['Exif'][41729] = str(exif_dict['Exif'][41729]).encode('utf-8')
|
||||||
|
|
||||||
|
if 37121 in exif_dict['Exif']:
|
||||||
|
cc = exif_dict['Exif'][37121]
|
||||||
|
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 50728 in exif_dict['Exif']:
|
||||||
|
cc = exif_dict['Exif'][50728]
|
||||||
|
if isinstance(cc, tuple):
|
||||||
|
if cc <= 1:
|
||||||
|
rational = f"({cc * 1000:.0f}, 1000)"
|
||||||
|
else:
|
||||||
|
rational = f"(1000, {cc * 1000:.0f})"
|
||||||
|
print(f"PIEXIF BUG workaround: 50728 {cc} is {type(cc)} - using {rational}")
|
||||||
|
exif_dict['Exif'][50728] = rational
|
||||||
|
|
||||||
|
return exif_dict
|
||||||
|
|
||||||
@login_required_if_public
|
@login_required_if_public
|
||||||
def new_image_form(request, path):
|
def new_image_form(request, path):
|
||||||
"""Manages a form to upload new images
|
"""Manages a form to upload new images
|
||||||
|
|
||||||
exif_dict = piexif.load(im.info["exif"])
|
exif_dict = piexif.load(im.info["exif"])
|
||||||
exif_dict = {"0th":zeroth_ifd, "Exif":exif_ifd, "GPS":gps_ifd, ...more}
|
exif_dict = {"0th":zeroth_ifd, "Exif":exif_ifd, "GPS":gps_ifd, ...more}
|
||||||
|
|
||||||
The "Exif.Image.NewSubfileType" tag (ID 41729) serves to identify
|
|
||||||
the type of image or subfile data contained in the image file
|
|
||||||
0: full resolution, 1: reduced resolution
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
THUMB_QUALITY = 70
|
THUMB_QUALITY = 70
|
||||||
IMAGE_QUALITY = 85
|
IMAGE_QUALITY = 85
|
||||||
@@ -238,12 +270,8 @@ def new_image_form(request, path):
|
|||||||
gps_annotations = extract_gps(gps_data)
|
gps_annotations = extract_gps(gps_data)
|
||||||
descrip += gps_annotations
|
descrip += gps_annotations
|
||||||
i = reorient_image(i, exif_dict)
|
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
|
|
||||||
try:
|
try:
|
||||||
# This is never written back into the images ?!!
|
exif = piexif.dump(fix_dump_bugs(exif_dict))
|
||||||
exif = piexif.dump(exif_dict)
|
|
||||||
# int(f"new_image_form() After DUMP {exif=}")
|
|
||||||
except:
|
except:
|
||||||
exif = None
|
exif = None
|
||||||
# date and time from exif data
|
# date and time from exif data
|
||||||
@@ -275,12 +303,16 @@ def new_image_form(request, path):
|
|||||||
if "exif" in i.info:
|
if "exif" in i.info:
|
||||||
exif_dict = piexif.load(i.info["exif"])
|
exif_dict = piexif.load(i.info["exif"])
|
||||||
exif_dict['GPS'] = gps_data # saved from before
|
exif_dict['GPS'] = gps_data # saved from before
|
||||||
exif_bytes = piexif.dump(exif_dict)
|
try:
|
||||||
|
exif_bytes = piexif.dump(fix_dump_bugs(exif_dict))
|
||||||
|
except Exception as e:
|
||||||
|
print(f"EXCEPTION {e}\n {exif_dict=}\n {gps_data=}")
|
||||||
|
raise
|
||||||
i.save(ib, format='JPEG', quality = IMAGE_QUALITY, exif=exif_bytes)
|
i.save(ib, format='JPEG', quality = IMAGE_QUALITY, exif=exif_bytes)
|
||||||
|
|
||||||
exif_dict = piexif.load(t.info["exif"])
|
exif_dict = piexif.load(t.info["exif"])
|
||||||
exif_dict['GPS'] = gps_data # saved from before
|
exif_dict['GPS'] = gps_data # saved from before
|
||||||
exif_bytes = piexif.dump(exif_dict)
|
exif_bytes = piexif.dump(fix_dump_bugs(exif_dict))
|
||||||
t.save(tb, format='JPEG', quality = THUMB_QUALITY, exif=exif_bytes)
|
t.save(tb, format='JPEG', quality = THUMB_QUALITY, exif=exif_bytes)
|
||||||
|
|
||||||
i.save(ib, format='JPEG', quality = IMAGE_QUALITY)
|
i.save(ib, format='JPEG', quality = IMAGE_QUALITY)
|
||||||
@@ -312,7 +344,7 @@ def new_image_form(request, path):
|
|||||||
(thumb_path, tb.getbuffer(), False),
|
(thumb_path, tb.getbuffer(), False),
|
||||||
],
|
],
|
||||||
# f"{change_message} - online adding of an image",
|
# f"{change_message} - online adding of an image",
|
||||||
f"Online adding of an image",
|
f"Online adding of an image to {path}",
|
||||||
editor # this works, a new who_are_you typed on the Image form is used as the git comment
|
editor # this works, a new who_are_you typed on the Image form is used as the git comment
|
||||||
)
|
)
|
||||||
except WriteAndCommitError as e:
|
except WriteAndCommitError as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user