You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
943 B
33 lines
943 B
6 years ago
|
#!/usr/bin/env python2
|
||
|
# tool to convert texts to images. needs an SVG as a template. See line 16
|
||
|
# (c) roel roscam abbing 2018
|
||
|
# gplv3
|
||
|
import os,base64,sys
|
||
|
count = 1
|
||
|
svg = open(sys.argv[1]).read()
|
||
|
text = open(sys.argv[2]).read()
|
||
|
|
||
|
if not os.path.exists('output'):
|
||
|
os.mkdir('output')
|
||
|
|
||
|
for sentence in text.split('\n'):
|
||
|
files = []
|
||
|
for word in sentence.split(' '):
|
||
|
fn = 'output/{}.svg'.format(base64.urlsafe_b64encode(word))
|
||
|
with open(fn, 'w') as f:
|
||
|
f.write(svg.replace('$what$', word))
|
||
|
files.append(fn)
|
||
|
if sentence:
|
||
|
try:
|
||
|
of = 'output/{}.gif'.format(str(count).zfill(3))
|
||
|
|
||
|
command = "convert -delay 1 -alpha set -dispose previous {} {}".format(" ".join(files),of)
|
||
|
print(command)
|
||
|
os.system(command)
|
||
|
count+=1
|
||
|
except:
|
||
|
print('skipped', sentence)
|
||
|
pass
|
||
|
os.system('rm {}'.format(' '.join(files)))
|
||
|
|