Using Python instead of Bash
Alain Ketterlin
alain at universite-de-strasbourg.fr.invalid
Sun May 31 10:02:59 EDT 2015
Cecil Westerhof <Cecil at decebal.nl> writes:
> 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.
> 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()
Maybe using check_call() would be simpler, but it will, well, check for
the exit code of convert/lpr (which you should do anyway). And I would
call that variable "threshold" instead of "treshold".
(What I don't see is the advantage you find in writing such scripts in
python instead of sh, but I guess you have your own reasons.)
-- Alain.
More information about the Python-list
mailing list