[Image-SIG] Re: PIL: jpeg comment

Fredrik Lundh fredrik at pythonware.com
Fri Jan 2 12:12:27 EST 2004


Jeff Kunce wrote:

> I don't know for sure, but try looking in the "app" attribute (a
> dictionary) of an image object. For example:
>   im = Image.open('myimage.jpg')
>   print im.app
> EXIF data is stored there, so maybe comments are, too

this has been added in 1.1.5, but earlier versions ignore the comment
markers.  here's a patch:

==== //modules/pil/PIL/JpegImagePlugin.py#6 - f:\pythonware\modules\pil\PIL\JpegImagePlugin.py ====
@@ -87,6 +89,15 @@
         else:
             self.info["adobe_transform"] = adobe_transform

+def COM(self, marker):
+    #
+    # Comment marker.  Store these in the APP dictionary.
+
+    s = self.fp.read(i16(self.fp.read(2))-2)
+
+    self.app["COM"] = s # compatibility
+    self.applist.append(("COM", s))
+
 def SOF(self, marker):
     #
     # Start of frame marker.  Defines the size and mode of the
@@ -208,7 +219,7 @@
     0xFFFB: ("JPG11", "Extension 11", None),
     0xFFFC: ("JPG12", "Extension 12", None),
     0xFFFD: ("JPG13", "Extension 13", None),
-    0xFFFE: ("COM", "Comment", Skip)
+    0xFFFE: ("COM", "Comment", COM)
 }

</F>






More information about the Image-SIG mailing list