Small maker of thumbnails and spitter-out of HTML for galleries.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

65 lines
2.0 KiB

#!/usr/bin/env python3
"""gallery-html - generate thumbnails and print html for images
Usage:
gallery-html [--source <pattern>...] [--output <dir>] [--base_url <url>] [-x <n>] [-y <n>] [--json <filename>] [--html <filename>] [--square] [--overwrite]
gallery-html (-h | --help)
gallery-html (-v | --version)
Options:
--source <pattern> Source directory or image file(s) to make gallery from
--output <dir> Parent directory on local filesystem for thumbnails
--base_url <url> Base URL for images
-x <n> Maximum width of thumbnails in pixels
-y <n> Maximum height of thumbnails in pixels
--json <filename> Render JSON output to filename
--html <filename> 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()