#!/usr/bin/env python3 """gallery-html - generate thumbnails and print html for images Usage: gallery-html [--source ...] [--output ] [--base_url ] [-x ] [-y ] [--json ] [--html ] [--square] [--overwrite] gallery-html (-h | --help) gallery-html (-v | --version) Options: --source Source directory or image file(s) to make gallery from --output Parent directory on local filesystem for thumbnails --base_url Base URL for images -x Maximum width of thumbnails in pixels -y Maximum height of thumbnails in pixels --json Render JSON output to filename --html Render HTML output to filename --square Fit thumbnails to squares --overwrite Replace existing thumbnail files -h --help Show this screen -v --version Display version """ from docopt import docopt from galleryhtml import galleryhtml import sys if __name__ == '__main__': args = docopt(__doc__, version='html-gallery 0.8.0') gh = galleryhtml.GalleryHTML() # This, friends, is kind of silly: if args['--base_url']: gh.base_url = args['--base_url'] if args['--output']: gh.output_dir = args['--output'] if args['-x']: gh.x = int(args['-x']) if args['-y']: gh.y = int(args['-y']) if args['--overwrite']: gh.overwrite = True if args['--square']: gh.square = True # Actually accumulate the images to be printed, either from a given source # or from the current directory. if args['--source']: gh.add_images_from(args['--source']) else: gh.add_images_from('.') # Write JSON data if requested: if args['--json']: with open(args['--json'], 'w') as f: f.write(gh.images_json()) # Write HTML data if requested: if args['--html']: with open(args['--html'], 'w') as f: f.write(gh.images_html()) sys.exit()