Using Python instead of Bash
Cecil Westerhof
Cecil at decebal.nl
Sun May 31 08:42:02 EDT 2015
I help someone that has problems reading. For this I take photo's of
text, use convert from ImageMagick to make a good contrast (original
paper is grey) and use lpr to print it a little bigger.
Normally I would implement this in Bash, but I thought it a good idea
to implement it in Python. This is my first try:
import glob
import subprocess
treshold = 66
count = 0
for input in sorted(glob.glob('*.JPG')):
count += 1
output = '{0:02d}.png'.format(count)
print('Going to convert {0} to {1}'.format(input, output))
p = subprocess.Popen(['convert', '-threshold', '{0}%'.format(treshold), input, output])
p.wait()
print('Going to print {0}'.format(output))
p = subprocess.Popen(['lpr', '-o', 'fit-to-page', '-o', 'media=A4', output])
p.wait()
There have to be some improvements: display before printing,
possibility to change threshold, … But is this a good start, or should
I do it differently?
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
More information about the Python-list
mailing list