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

  1. #!/usr/bin/env python3
  2. """gallery-html - generate thumbnails and print html for images
  3. Usage:
  4. gallery-html [--source <pattern>...] [--output <dir>] [--base_url <url>] [-x <n>] [-y <n>] [--json <filename>] [--html <filename>] [--square] [--overwrite]
  5. gallery-html (-h | --help)
  6. gallery-html (-v | --version)
  7. Options:
  8. --source <pattern> Source directory or image file(s) to make gallery from
  9. --output <dir> Parent directory on local filesystem for thumbnails
  10. --base_url <url> Base URL for images
  11. -x <n> Maximum width of thumbnails in pixels
  12. -y <n> Maximum height of thumbnails in pixels
  13. --json <filename> Render JSON output to filename
  14. --html <filename> Render HTML output to filename
  15. --square Fit thumbnails to squares
  16. --overwrite Replace existing thumbnail files
  17. -h --help Show this screen
  18. -v --version Display version
  19. """
  20. from docopt import docopt
  21. from galleryhtml import galleryhtml
  22. import sys
  23. if __name__ == '__main__':
  24. args = docopt(__doc__, version='html-gallery 0.8.0')
  25. gh = galleryhtml.GalleryHTML()
  26. # This, friends, is kind of silly:
  27. if args['--base_url']:
  28. gh.base_url = args['--base_url']
  29. if args['--output']:
  30. gh.output_dir = args['--output']
  31. if args['-x']:
  32. gh.x = int(args['-x'])
  33. if args['-y']:
  34. gh.y = int(args['-y'])
  35. if args['--overwrite']:
  36. gh.overwrite = True
  37. if args['--square']:
  38. gh.square = True
  39. # Actually accumulate the images to be printed, either from a given source
  40. # or from the current directory.
  41. if args['--source']:
  42. gh.add_images_from(args['--source'])
  43. else:
  44. gh.add_images_from('.')
  45. # Write JSON data if requested:
  46. if args['--json']:
  47. with open(args['--json'], 'w') as f:
  48. f.write(gh.images_json())
  49. # Write HTML data if requested:
  50. if args['--html']:
  51. with open(args['--html'], 'w') as f:
  52. f.write(gh.images_html())
  53. sys.exit()