JPEG comments and PIL

Fredrik Lundh fredrik at pythonware.com
Sat Sep 13 04:55:07 EDT 2003


Eugene Morozov wrote:

> Is it possible to manipulate JPEG comments using PIL? I
> didn't find corresponding methods in the PIL library. I
> just want to write yet another image viewer and editor
> (similar to gthumb only crossplatform and with better
> comment editing interface and web album generation
> feature ;)) which stores comments in the JPEG images
> themselves.

as of 1.1.4, PIL can read APP markers (see the app/applist attributes
of the Jpeg image object), but you cannot write them out again.

COM markers are not supported at all, but reading them should be trivial;
just change

    0xFFFE: ("COM", "Comment", Skip)

to

    0xFFFE: ("COM", "Comment", COM)

in PIL/JpegImagePlugin.py, and define this function before the
start of the MARKER table:

def COM(self, marker):
    s = self.fp.read(i16(self.fp.read(2))-2)
    self.app["COM"] = s # compatibility
    self.applist.append(("COM", s))

</F>








More information about the Python-list mailing list