fix cover for non utf-8 txt files

This commit is contained in:
j 2015-03-08 01:38:35 +05:30
parent bbf0649cd6
commit 701d032753

View file

@ -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'):