From 603f2a226f43a500bceb9987ee319d6cc1da3f8a Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Thu, 7 Mar 2013 11:59:52 +0000 Subject: [PATCH] Added the ``named`` method to a Tiffs tag getter. --- PIL/TiffImagePlugin.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/PIL/TiffImagePlugin.py b/PIL/TiffImagePlugin.py index 03d4c94a3..6cda553e2 100644 --- a/PIL/TiffImagePlugin.py +++ b/PIL/TiffImagePlugin.py @@ -216,11 +216,30 @@ class ImageFileDirectory(collections.MutableMapping): self.reset() def reset(self): + #: Tags is an incomplete dictionary of the tags of the image. + #: For a complete dictionary, use teh as_dict method. self.tags = {} self.tagdata = {} self.tagtype = {} # added 2008-06-05 by Florian Hoech self.next = None + def __str__(self): + return str(self.as_dict()) + + def as_dict(self): + """Return a dictionary of the image's tags.""" + return dict(self.items()) + + def named(self): + """Returns the complete tag dictionary, with named tags where posible.""" + from . import TiffTags + result = {} + for tag_code, value in self.items(): + tag_name = TiffTags.TAGS.get(tag_code, tag_code) + result[tag_name] = value + return result + + # dictionary API def __len__(self):