On 2015-05-31, Cecil Westerhof <ce...@decebal.nl> wrote: > 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.
Why? Is it difficult to do/maintain in Bash? If you want to write Python, then you should write Python. You're still writing Bash, so you should probably do it in Bash. If you just want to invoke a set of external programs on a set of files, then Bash is probably the right language to use: that's pretty much what Bash is for: manipulating files by invoking other programs. > 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? If all the work is being done by making a series of calls to subprocess, then you should think about using bash instead. If you really do want to do this in Python, you can use a Python binding to the ImageMagick libraries: https://wiki.python.org/moin/ImageMagick http://www.imagemagick.org/download/python/ http://stackoverflow.com/questions/7895278/can-i-access-imagemagick-api-with-python Or maybe you can use Pillow: http://pillow.readthedocs.org/ https://github.com/python-pillow/Pillow https://python-pillow.github.io/ -- Grant Edwards grant.b.edwards Yow! Of course, you at UNDERSTAND about the PLAIDS gmail.com in the SPIN CYCLE -- -- https://mail.python.org/mailman/listinfo/python-list