Browse Source

add options for json & html file output

master
Brennen Bearnes 5 years ago
parent
commit
1f77fcafd3
6 changed files with 68 additions and 44 deletions
  1. +9
    -8
      README.md
  2. +17
    -12
      bin/gallery-html
  3. +8
    -8
      galleryhtml/galleryhtml.py
  4. +33
    -0
      install_for_dev_and_test.sh
  5. +1
    -1
      setup.py
  6. +0
    -15
      test.sh

+ 9
- 8
README.md View File

@ -50,19 +50,20 @@ gallery-html usage
gallery-html - generate thumbnails and print html for images
Usage:
gallery-html [--source=<pattern>...] [--output=<dir>] [--base_url=<url>] [-x=<pixels>] [-y=<pixels>] [--json] [--overwrite]
gallery-html [--source <pattern>...] [--output <dir>] [--base_url <url>] [-x <n>] [-y <n>] [--json <filename>] [--html <filename>] [--overwrite]
gallery-html (-h | --help)
gallery-html (-v | --version)
Options:
-h --help Show this screen
--json Render JSON output instead of HTML
--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
--overwrite Replace existing thumbnail files
--base_url=<url> Base URL for images
--output=<dir> Path on local filesystem for images and thumbs
--source=<pattern> Source directory or image file(s) to make gallery from
-x=<pixels> Maximum width of thumbnails
-y=<pixels> Maximum height of thumbnails
-h --help Show this screen
-v --version Display version
<!-- end -->


+ 17
- 12
bin/gallery-html View File

@ -2,19 +2,20 @@
"""gallery-html - generate thumbnails and print html for images
Usage:
gallery-html [--source=<pattern>...] [--output <dir>] [--base_url <url>] [-x <n>] [-y <n>] [--json] [--overwrite]
gallery-html [--source <pattern>...] [--output <dir>] [--base_url <url>] [-x <n>] [-y <n>] [--json <filename>] [--html <filename>] [--overwrite]
gallery-html (-h | --help)
gallery-html (-v | --version)
Options:
-h --help Show this screen
--json Render JSON output instead of HTML
--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
--overwrite Replace existing thumbnail files
--base_url=<url> Base URL for images
--output=<dir> Path on local filesystem for images and thumbs
--source=<pattern> Source directory or image file(s) to make gallery from
-x=<n> Maximum width of thumbnails in pixels
-y=<n> Maximum height of thumbnails in pixels
-h --help Show this screen
-v --version Display version
"""
@ -47,10 +48,14 @@ if __name__ == '__main__':
else:
gh.add_images_from('.')
# JSON data if requested, HTML otherwise.
# Write JSON data if requested:
if args['--json']:
gh.print_images_json()
else:
gh.print_images_html()
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()

+ 8
- 8
galleryhtml/galleryhtml.py View File

@ -14,8 +14,8 @@ class GalleryHTML:
self.base_url = ""
self.extensions = ['JPG', 'jpg', 'jpeg', 'png', 'gif', 'bmp']
self.image_list = []
self.x = 256
self.y = 256
self.x = 500
self.y = 500
self.overwrite = False
def add_images_from(self, source):
@ -45,18 +45,18 @@ class GalleryHTML:
return images
def print_images_html(self):
"""Print HTML for an image list."""
def images_html(self):
"""Return HTML for an image list."""
html_output = ''
for display_image in self.image_list:
(x, y) = display_image[2]
html_output += a(img(src=display_image[0], width=x, height=y),
href=display_image[1]).render() + "\n"
print(html_output.strip())
return html_output.strip()
def print_images_json(self):
"""Print JSON for an image list."""
print(json.dumps(self.image_list))
def images_json(self):
"""Return JSON for an image list."""
return json.dumps(self.image_list)
def _handle_exif(self, source_image):
"""


+ 33
- 0
install_for_dev_and_test.sh View File

@ -0,0 +1,33 @@
#!/usr/bin/env bash
# This probably isn't necessary:
sudo pip3 install -e .
cd test
if [[ -d Thumbs ]]; then
echo "deleting any existing thumbs"
rm -rf Thumbs
fi
if [[ -f index.html ]]; then
echo "deleting index.html"
rm index.html
fi
if [[ -f index.json ]]; then
echo "deleting index.json"
rm index.json
fi
gallery-html --base_url "https://p1k3.com/photos/example/" --html index.html
tail -3 index.html
echo
ls Thumbs
gallery-html --json index.json
tail -3 index.json
echo
gallery-html --overwrite -x 500 -y 500
ls Thumbs

+ 1
- 1
setup.py View File

@ -1,7 +1,7 @@
from setuptools import setup
setup(name='galleryhtml',
version='0.4.0',
version='0.5.0',
description='Generate thumbnails for images and print a simple HTML gallery',
url='http://github.com/brennen/galleryhtml',
author='Brennen Bearnes',


+ 0
- 15
test.sh View File

@ -1,15 +0,0 @@
#!/usr/bin/env bash
# This probably isn't necessary:
sudo pip3 install -e .
cd test
if [[ -d Thumbs ]]; then
echo "deleting any existing thumbs"
rm -rf Thumbs
fi
gallery-html --base_url "https://p1k3.com/photos/example/"
ls Thumbs
gallery-html --json
gallery-html --overwrite -x 500 -y 500
ls Thumbs

Loading…
Cancel
Save