[Image-SIG] PNG patch for reading zTXt chunks
Lowell Alleman
lowell at allemansonline.com
Thu Feb 22 22:36:37 CET 2007
Here is a patch to add support for reading compressed text chunks
(zTXt) and storing them in the info dictionary. With this patch, both
compressed and uncompressed (tEXt) text chunks can be accessed uniformly.
I've come across some text tag discussions on this mailing list from
many years ago. Since then, it appears that some support has been
added, but not for reading zTXt chunks. Since it has been a while,
I'm going to ask that support for reading zTXt chunks be considered again.
Previous discussions (patches):
http://mail.python.org/pipermail/image-sig/1998-July/000529.html
http://mail.python.org/pipermail/image-sig/1999-May/000737.html
Here is my patch. I borrowed ideas from the two patches listed
above. It should apply cleanly against the 1.1.6 release.
diff -Naur Imaging-1.1.6/PIL/PngImagePlugin.py Imaging-LCA/PIL/PngImagePlugin.py
--- Imaging-1.1.6/PIL/PngImagePlugin.py 2007-02-21 10:55:03.000000000 -0500
+++ Imaging-LCA/PIL/PngImagePlugin.py 2007-02-21 13:27:15.000000000 -0500
@@ -254,6 +254,19 @@
self.im_info[k] = v
return s
+ def chunk_zTXt(self, pos, len):
+ s = ImageFile._safe_read(self.fp, len)
+ (k, v) = string.split(s, "\0", 1)
+ comp_method = ord(v[0])
+ v = v[1:]
+ if comp_method != 0:
+ raise SyntaxError, "Unknown compression method %i in zTXt chunk" % comp_method
+ import zlib
+ v = zlib.decompress(v)
+ self.im_info[k] = v
+ return s
+
# --------------------------------------------------------------------
# PNG reader
Thanks,
- Lowell Alleman
-------------- next part --------------
A non-text attachment was scrubbed...
Name: png_read_zTXt.patch
Type: text/x-patch
Size: 800 bytes
Desc: not available
Url : http://mail.python.org/pipermail/image-sig/attachments/20070222/eb571cb7/attachment.bin
More information about the Image-SIG
mailing list