[Image-SIG] Patch: multiple IPTC keywords for a single tag

Eric Bruning enrickyb at ou.edu
Wed Mar 7 01:13:26 CET 2007


According to the specification, some IPTC tags can be repeated, e.g.,  
tag 2:25 (keywords). PIL 1.1.6 only retained the last instance of  
that tag. Below is a patch to store all tags. If there are multiple  
tag instances, they are stored in a (python) list. Single tag  
instances remain as strings.

The mixed types stored in the info dictionary present a bit of an  
access challenge for the end user. I wasn't sure how else to handle  
this. I'd be happy to implement a different solution if one were  
proposed.

Thanks,
Eric

  diff -u Original/PIL/IptcImagePlugin.py Modified/PIL/ 
IptcImagePlugin.py

--- Original/PIL/IptcImagePlugin.py        2006-12-03  
05:37:15.000000000 -0600
+++ Modified/PIL/IptcImagePlugin.py        2007-03-06  
12:08:48.000000000 -0600
@@ -116,11 +116,17 @@
              if not tag or tag == (8,10):
                  break
              if size:
-                self.info[tag] = self.fp.read(size)
+                tagdata = self.fp.read(size)
              else:
-                self.info[tag] = None
-            # print tag, self.info[tag]
-
+                tagdata = None
+            if tag in self.info.keys() :
+                try:
+                    self.info[tag].append(tagdata)
+                except:
+                    self.info[tag] = [self.info[tag], tagdata]
+            else:
+                self.info[tag] = tagdata
+
          # mode
          layers = ord(self.info[(3,60)][0])
          component = ord(self.info[(3,60)][1])



More information about the Image-SIG mailing list