Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Creates files for interleaving from a series of even- or odd-page scan images
#!/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
You can’t perform that action at this time.