From 6d9d4af1921e63e937b7426736a3ce1751af4c68 Mon Sep 17 00:00:00 2001 From: Melon Mouse <73140350+melonmouse@users.noreply.github.com> Date: Fri, 16 Sep 2022 10:48:37 +0200 Subject: [PATCH 1/4] Add inverse mappings for exif tags. A nicer solution would be to switch to an enum with the right values, but this is the quick win. --- src/PIL/ExifTags.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/PIL/ExifTags.py b/src/PIL/ExifTags.py index 7da2ddae5a7..15e8010b6f2 100644 --- a/src/PIL/ExifTags.py +++ b/src/PIL/ExifTags.py @@ -293,6 +293,11 @@ } """Maps EXIF tags to tag names.""" +TAG_CODES = { + # possibly incomplete + tag_name: tag_code for tag_code, tag_name in TAGS.items() +} +"""Maps tag names to EXIF tags.""" GPSTAGS = { 0: "GPSVersionID", @@ -329,3 +334,6 @@ 31: "GPSHPositioningError", } """Maps EXIF GPS tags to tag names.""" + +GPS_CODES = {gps_name: gps_code for gps_code, gps_name in GPSTAGS.items()} +"""Maps tag names to EXIF GPS tags.""" From ce905dea74387b1e369b323acc183f6e1bdb3506 Mon Sep 17 00:00:00 2001 From: Melon Mouse <73140350+melonmouse@users.noreply.github.com> Date: Fri, 16 Sep 2022 10:56:45 +0200 Subject: [PATCH 2/4] Add include inverse mappings to ExifTags docs. --- docs/reference/ExifTags.rst | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/docs/reference/ExifTags.rst b/docs/reference/ExifTags.rst index 4567d4d3e79..e2241dc2f9e 100644 --- a/docs/reference/ExifTags.rst +++ b/docs/reference/ExifTags.rst @@ -4,25 +4,45 @@ :py:mod:`~PIL.ExifTags` Module ============================== -The :py:mod:`~PIL.ExifTags` module exposes two dictionaries which +The :py:mod:`~PIL.ExifTags` module exposes four dictionaries which provide constants and clear-text names for various well-known EXIF tags. .. py:data:: TAGS :type: dict - The TAG dictionary maps 16-bit integer EXIF tag enumerations to - descriptive string names. For instance: + The TAGS dictionary maps 16-bit integer EXIF tag enumerations to + descriptive string names. For instance: >>> from PIL.ExifTags import TAGS >>> TAGS[0x010e] 'ImageDescription' + +.. py:data:: TAG_CODES + :type: dict + + The TAG_CODES dictionary maps descriptive string names to 16-bit integer EXIF + tag enumerations. For instance: + + >>> from PIL.ExifTags import TAG_CODES + >>> TAG_CODES['ImageDescription'] + 0x010e .. py:data:: GPSTAGS :type: dict The GPSTAGS dictionary maps 8-bit integer EXIF gps enumerations to - descriptive string names. For instance: + descriptive string names. For instance: >>> from PIL.ExifTags import GPSTAGS >>> GPSTAGS[20] 'GPSDestLatitude' + +.. py:data:: GPS_CODES + :type: dict + + The GPS_CODES dictionary maps descriptive string names to 8-bit integer EXIF + gps enumerations. For instance: + + >>> from PIL.ExifTags import GPSTAGS + >>> GPS_CODES['GPSDestLatitude'] + 20 From 50bbf11c02017fae577fca3cbd0f65465c48466a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 16 Sep 2022 09:01:35 +0000 Subject: [PATCH 3/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/PIL/ExifTags.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PIL/ExifTags.py b/src/PIL/ExifTags.py index 15e8010b6f2..925cafbe3b7 100644 --- a/src/PIL/ExifTags.py +++ b/src/PIL/ExifTags.py @@ -295,7 +295,8 @@ TAG_CODES = { # possibly incomplete - tag_name: tag_code for tag_code, tag_name in TAGS.items() + tag_name: tag_code + for tag_code, tag_name in TAGS.items() } """Maps tag names to EXIF tags.""" From 793fb76b611ad59792399cccf8eb638c6c3cc18f Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 16 Sep 2022 19:12:46 +1000 Subject: [PATCH 4/4] Removed trailing whitespace --- docs/reference/ExifTags.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/reference/ExifTags.rst b/docs/reference/ExifTags.rst index e2241dc2f9e..5827757f435 100644 --- a/docs/reference/ExifTags.rst +++ b/docs/reference/ExifTags.rst @@ -16,7 +16,7 @@ provide constants and clear-text names for various well-known EXIF tags. >>> from PIL.ExifTags import TAGS >>> TAGS[0x010e] 'ImageDescription' - + .. py:data:: TAG_CODES :type: dict @@ -36,7 +36,7 @@ provide constants and clear-text names for various well-known EXIF tags. >>> from PIL.ExifTags import GPSTAGS >>> GPSTAGS[20] 'GPSDestLatitude' - + .. py:data:: GPS_CODES :type: dict