fix cover for non utf-8 txt files
This commit is contained in:
parent
bbf0649cd6
commit
701d032753
1 changed files with 12 additions and 1 deletions
|
@ -12,9 +12,19 @@ root_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))
|
||||||
os.chdir(root_dir)
|
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):
|
def render(infile, outfile):
|
||||||
|
|
||||||
with open(infile) as f:
|
with open(infile, 'rb') as f:
|
||||||
|
|
||||||
image_size = (768, 1024)
|
image_size = (768, 1024)
|
||||||
margin = 64
|
margin = 64
|
||||||
|
@ -27,6 +37,7 @@ def render(infile, outfile):
|
||||||
image = Image.new('L', image_size, (255))
|
image = Image.new('L', image_size, (255))
|
||||||
|
|
||||||
for line in f:
|
for line in f:
|
||||||
|
line = decode_line(line)
|
||||||
|
|
||||||
for line_ in line.strip().split('\r'):
|
for line_ in line.strip().split('\r'):
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue