Save detected non-Latin1 characters as iTXt to preserve them.

This commit is contained in:
Fredrik Tolf 2014-07-23 07:43:52 -07:00
parent 823d377e47
commit a9f4e30641

View File

@ -191,12 +191,15 @@ class PngInfo:
return self.add_itxt(key, value, value.lang, value.tkey, bool(zip))
# The tEXt chunk stores latin-1 text
if not isinstance(value, bytes):
try:
value = value.encode('latin-1', 'strict')
except UnicodeError:
return self.add_itxt(key, value, zip=bool(zip))
if not isinstance(key, bytes):
key = key.encode('latin-1', 'strict')
if not isinstance(value, bytes):
value = value.encode('latin-1', 'replace')
if zip:
import zlib
self.add(b"zTXt", key + b"\0\0" + zlib.compress(value))