Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.pionier.net.pl!feed.xsnews.nl!border03.ams.xsnews.nl!feeder03.ams.xsnews.nl!abp002.ams.xsnews.nl!frontend-F09-14.ams.news.kpn.nl From: Cecil Westerhof Newsgroups: comp.lang.python Subject: Using Python instead of Bash Organization: Decebal Computing X-Face: "(y8cC@tg_12{">GF'UXTW]FHI2wMiZNrnf'1EFQ&O#$m:f#O7+7}kR,v+Pti8=Vi/Z"g^?b"E X-Homepage: http://www.decebal.nl/ Date: Sun, 31 May 2015 14:42:02 +0200 Message-ID: <87h9qsnckl.fsf@Equus.decebal.nl> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:5ybzKO/LxZ2TDXdG6Vy0IF7MJtc= MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Lines: 29 NNTP-Posting-Host: 81.207.62.244 X-Trace: 1433076357 news.kpn.nl 25013 81.207.62.244@kpn/81.207.62.244:52809 Xref: csiph.com comp.lang.python:91570 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