Created
March 22, 2017 19:35
-
-
Save mmagnus/f071b84a6fa85c3c5ac15e93dc4b5ccf to your computer and use it in GitHub Desktop.
scanify.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import argparse | |
def get_parser(): | |
"""Get parser of arguments""" | |
parser = argparse.ArgumentParser() | |
# parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) | |
parser.add_argument('file')#, nargs='+') | |
return parser | |
def scanify(fn): | |
"""Scanify a file. | |
Credits http://tex.stackexchange.com/questions/94523/simulate-a-scanned-paper | |
http://www.imagemagick.org/Usage/photos/#color-in | |
.. warning :: required imagemagick | |
""" | |
nfn = os.path.splitext(fn)[0] + '_scan.png' | |
#print('from', fn) | |
#print('to', nfn ) | |
os.system('convert "' + fn + '" \( +clone -blur 0x1 \) +swap -compose divide -composite -linear-stretch 5%x0% "' + nfn + '"') | |
print('%s save' % nfn) | |
from IPython.display import Image | |
return Image(filename=nfn) | |
if __name__ == '__main__': | |
parser = get_parser() | |
args = parser.parse_args() | |
fn = args.file | |
scanify(fn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment