From 701d0327533d0da8838b738006a34d5028312958 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 8 Mar 2015 01:38:35 +0530 Subject: [PATCH] fix cover for non utf-8 txt files --- txt.js/txt.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/txt.js/txt.py b/txt.js/txt.py index d34e5c4..f4db38b 100755 --- a/txt.js/txt.py +++ b/txt.js/txt.py @@ -12,9 +12,19 @@ root_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__))) os.chdir(root_dir) +def decode_line(line): + try: + line = line.decode('utf-8') + except: + try: + line = line.decode('latin-1') + except: + line = line.decode('utf-8', errors='replace') + return line + def render(infile, outfile): - with open(infile) as f: + with open(infile, 'rb') as f: image_size = (768, 1024) margin = 64 @@ -27,6 +37,7 @@ def render(infile, outfile): image = Image.new('L', image_size, (255)) for line in f: + line = decode_line(line) for line_ in line.strip().split('\r'):