Created
March 14, 2015 11:35
-
-
Save gareth8118/c792fe58ed4065821968 to your computer and use it in GitHub Desktop.
Creates files for interleaving from a series of even- or odd-page scan images
This file contains 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 shutil | |
import argparse | |
def interleave_pages(startindex, stopindex, startpage, srcpath, dstpath): | |
"""Remap a series of pages to interleaved destinations. | |
""" | |
if startindex < stopindex: | |
increment = 1 | |
else: | |
increment = -1 | |
page = startpage | |
for index in xrange(startindex, stopindex+increment, increment): | |
srcfile = "%03d.jpg" % (index) | |
dstfile = "%03d_from_%03d.jpg" % (page, index) | |
print "Creating %s" % (dstfile) | |
shutil.copy(srcpath + '/' + srcfile, dstpath + '/' + dstfile) | |
page += 2 | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('srcpath', | |
help="Path to the input images") | |
parser.add_argument('dstpath', | |
help="Path to the output images") | |
parser.add_argument('startindex', | |
type=int, | |
help="index of the starting page image") | |
parser.add_argument('stopindex', | |
type=int, | |
help="index of the ending page image") | |
parser.add_argument('startpage', | |
type=int, | |
help="output index of the page " | |
"corresponding to startindex") | |
args = parser.parse_args() | |
interleave_pages(args.startindex, | |
args.stopindex, | |
args.startpage, | |
args.srcpath, | |
args.dstpath) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment