JPEG comments and PIL

Fredrik Lundh fredrik at
Sat Sep 13 10:55:07 CEST 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)


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

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

def COM(self, marker):
    s =["COM"] = s # compatibility
    self.applist.append(("COM", s))


More information about the Python-list mailing list