[Image-SIG] PATCH: PngImagePlugin.py

Greg Couch gregc@cgl.ucsf.EDU
Tue, 3 Dec 2002 18:30:42 -0800 (PST)


Enclosed is patch that adds support for the PNG 1.2 standard text tags
so you can annotate your PNG files.  This code only works with Python
2.0 and later due to use of the string title method, tag.title().  For
Python 1.5, you would need to use string.capwords(tag) instead.

	Greg Couch
	UCSF Computer Graphics Lab
	gregc@cgl.ucsf.edu

P.S. The comment for my last TIFF patch might mention that Adobe Illustrator
     won't open a TIFF file without the compression tag.

-----
*** PngImagePlugin.py	2002/12/04 00:22:21	1.1
--- PngImagePlugin.py	2002/12/04 01:26:30
***************
*** 420,425 ****
--- 420,433 ----
            chr(0),                               # 10: compression
            chr(0),                               # 11: filter category
            chr(0))                               # 12: interlace flag
+ 
+     # output standard text chunks (PNG 1.2 specification section 4.3)
+     for tag in ['title', 'author', 'description', 'copyright', 'creation time', 'software', 'disclaimer', 'warning', 'source', 'comment']:
+ 	if not im.encoderinfo.has_key(tag):
+ 	    continue
+ 	# TODO: if type(im.encoderinfo[tag]) is unicode, then use iTXt
+ 	# TODO: if len(im.encoderinfo[tag] > 1024, then use zTXt
+ 	chunk(fp, "tEXt", tag.title(), chr(0), im.encoderinfo[tag])
  
      if im.mode == "P":
          chunk(fp, "PLTE", im.im.getpalette("RGB"))