Skip to content

Commit 7994e61

Browse files
committed
feat: add exif orientation tag value to mss docs
1 parent 6a210b1 commit 7994e61

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

dataimporter/emu/views/mss.py

+14
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ def transform(self, record: SourceRecord) -> dict:
6666
"file": identifiers[0],
6767
}
6868

69+
# add the orientation tag data from exif if specified
70+
tags = record.get_all_values("ExiTag", reduce=False)
71+
tag_values = record.get_all_values("ExiValue", reduce=False)
72+
if tags and tag_values:
73+
try:
74+
# the orientation tag is 274 (0x0112), so look up the index of that in
75+
# the tags tuple and then the value will be at the same index in the
76+
# values tuple. Because EMu, the value can be either a number or the
77+
# text version, e.g. "7" or "Rotate 270 CW"
78+
data["orientation"] = tag_values[tags.index("274")]
79+
except ValueError:
80+
# no orientation in the tags so there's nothing to do
81+
pass
82+
6983
# add old MAM asset IDs if found
7084
old_asset_id = record.get_first_value("GenDigitalMediaId")
7185
if old_asset_id and old_asset_id != "Pending":

tests/emu/views/test_mss.py

+14
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def test_transform(mss_view: MSSView):
3939
"file": "BM000019319.tif",
4040
"width": 6638,
4141
"height": 10199,
42+
"orientation": "Horizontal (normal)",
4243
"derivatives": [
4344
{"file": "BM000019319.thumb.jpg", "width": 59, "height": 90},
4445
{"file": "BM000019319.120x10199.jpeg", "width": 120, "height": 184},
@@ -67,3 +68,16 @@ def test_transform_no_derivatives(mss_view: MSSView):
6768
"width": 6638,
6869
"height": 10199,
6970
}
71+
72+
73+
def test_transform_no_orientation(mss_view: MSSView):
74+
data = SAMPLE_IMAGE_DATA.copy()
75+
# remove the exif tag in our sample data which stores the orientation value (and all
76+
# the associated tag and tag name bits EMu exports)
77+
for field in ["ExiTag", "ExiName", "ExiValue"]:
78+
# in the test data the orientation tag is the 8th element of the exif lists
79+
del data[field][8]
80+
record = SourceRecord(SAMPLE_IMAGE_ID, data, "test")
81+
82+
data = mss_view.transform(record)
83+
assert "orientation" not in data

0 commit comments

Comments
 (0)