From 83560c97b635622897c5c801d3960579bfdf732f Mon Sep 17 00:00:00 2001 From: Nils Date: Sun, 6 Nov 2016 12:40:01 +0100 Subject: first commit --- .gitignore | 1 + README.md | 51 ++++++++++++ gallery.sh | 256 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 308 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100755 gallery.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..496ee2c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..95d2042 --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +gallery.sh +========== + +Bash Script to generate static web galleries. No server-side programs (i.e. PHP, MySQL) required. + +Overview +-------- +`gallery.sh` is simple bash shell script which generates static html thumbnail (image, photo) galleries using the `convert` and `jhead` command-line utilities. +It requires no special server-side script to run to view image galleries because everything is pre-rendered. +It offers several features: +* Responsive layout +* Thumbnails which fill the browser efficiently +* Download the original image file +* Nice and simple Bootstrap CSS layout +* Locally previewable galleries by accessing images locally (e.g. file:///home/nils/pics/gallery/index.html) +* JPEG header EXIF data extraction +* Auto-rotation of veritcal images + +This combination of features makes a better user experience than pretty much all the big online photo hosts. +All you need is a place to host your plain html and jpeg files. This can also be Amazon S3. + +Requirements +------------ +* ImageMagick (http://www.imagemagick.org/) for the `convert` utility. +* JHead (https://wiki.ubuntuusers.de/JHead/) for EXIF data extraction + +On a debian-based system (Ubuntu), just run `apt-get install imagemagick jhead` as root. + +Under macOS you can install it with MacPort (https://www.macports.org/): `sudo port install imagemagick jhead` + +Usage +----- + + gallery.sh [-t ] [-h] + +`gallery.sh` works in the **current** directory. Just load the index.html in a browser see the output. + +The directory should contain a bunch of JPEG (.jpg or .JPG) files. It does not work recursively. +ZIP files (.zip or .ZIP) and movies (.mov or .MOV) are also considered. They appear as a download button in the gallery. + +Screenshots +----------- + +![Gallery](http://i.imgur.com/TOxgphm.jpg) + +![Image](http://i.imgur.com/iqQzst2.jpg) + +License +------- +GNU Public License version 3. +Please feel free to fork and modify this on GitHub (https://github.com/Cyclenerd/gallery_shell). \ No newline at end of file diff --git a/gallery.sh b/gallery.sh new file mode 100755 index 0000000..b655339 --- /dev/null +++ b/gallery.sh @@ -0,0 +1,256 @@ +#!/bin/bash + +# gallery.sh +# Author: Nils Knieling - https://github.com/Cyclenerd/gallery_shell +# Inspired by: Shapor Naghibzadeh - https://github.com/shapor/bashgal + +######################################################################################### +#### Configuration Section +######################################################################################### + +height_small=187 +height_large=768 +quality=85 +thumbdir=__thumbs +htmlfile=index.html +title="Gallery" +footer='Created with <a href="https://github.com/Cyclenerd/gallery_shell">gallery.sh</a>' + +# Use convert from ImageMagick +convert="convert" +# Use JHead for EXIF Information +exif="jhead" + +# Bootstrap (currently v3.3.7) +# Latest compiled and minified CSS +stylesheet="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" + +downloadicon='<span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span>' +movieicon='<span class="glyphicon glyphicon-film" aria-hidden="true"></span>' +homeicon='<span class="glyphicon glyphicon-home" aria-hidden="true"></span>' + +function debug { + return 0 # 0=enable, 1=disable debugging output +} + +######################################################################################### +#### End Configuration Section +######################################################################################### + + +me=$(basename "$0") +datetime=$(date -u "+%Y-%m-%d %H:%M:%S") +datetime+=" UTC" + +function usage { + echo "usage: $me [-t <title>] [-h]" + echo " [-t <title>] sets the title (default: $title)" + echo " [-h] displays help (this message)" +} + +while getopts ":t:h" opt; do + case $opt in + t) + title="$OPTARG" + ;; + h) + usage + exit 0 + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + esac +done + +debug && echo "- $me : $datetime" + +### Check Commands +command -v $convert >/dev/null 2>&1 || { echo >&2 "!!! $convert it's not installed. Aborting."; exit 1; } +command -v $exif >/dev/null 2>&1 || { echo >&2 "!!! $exif it's not installed. Aborting."; exit 1; } + +### Create Folders +[[ -d $thumbdir ]] || mkdir $thumbdir || exit 2 + +heights[0]=$height_small +heights[1]=$height_large +for res in ${heights[*]}; do + [[ -d $thumbdir/$res ]] || mkdir -p $thumbdir/$res || exit 3 +done + +#### Create Startpage +debug && echo "+" $htmlfile +cat > "$htmlfile" << EOF +<!DOCTYPE HTML> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>$title + + + + + +
+
+
+ +
+
+EOF + +### Photos (JPG) +if [[ $(ls -l | grep -i jpg | wc -l) -gt 0 ]]; then + +echo '
' >> "$htmlfile" +## Generate Images +numfiles=0 +for filename in *.[jJ][pP][gG]; do + debug && echo -n "+ $filename: " + filelist[$numfiles]=$filename + let numfiles++ + for res in ${heights[*]}; do + debug && echo -n "$thumbdir/$res " + if [[ ! -s $thumbdir/$res/$filename ]]; then + $convert -auto-orient -strip -quality $quality -resize x$res "$filename" "$thumbdir/$res/$filename" + fi + done + debug && echo + cat >> "$htmlfile" << EOF +
+

+ +

+

+
+EOF +[[ $(( $numfiles % 4 )) -eq 0 ]] && echo '
' >> "$htmlfile" +done +echo '
' >> "$htmlfile" + +## Generate the HTML Files for Images in thumbdir +file=0 +while [[ $file -lt $numfiles ]]; do + filename=${filelist[$file]} + prev= next= + [[ $file -ne 0 ]] && prev=${filelist[$((file - 1))]} + [[ $file -ne $((numfiles - 1)) ]] && next=${filelist[$((file + 1))]} + imagehtmlfile=$thumbdir/$filename.html + exifinfo=$($exif "$filename") + filesize=$(ls -lah "$filename" | awk '{ print $5}') + cat > "$imagehtmlfile" << EOF + + + + +$filename + + + + + +
+
+
+ +
+
+EOF + + # Pager + echo '
' >> "$imagehtmlfile" + + cat >> "$imagehtmlfile" << EOF +
+
+

+
+
+ +EOF + + # EXIF + if [[ $exifinfo ]]; then + cat >> "$imagehtmlfile" << EOF +
+
+
+$exifinfo
+
+
+
+EOF + fi + + # Footer + cat >> "$imagehtmlfile" << EOF +
+ + +EOF + let file++ +done + +fi + +### Movies (MOV) +if [[ $(ls -l | grep -i mov | wc -l) -gt 0 ]]; then + cat >> "$htmlfile" << EOF +
+
+ +
+
+
+
+EOF + for filename in *.[mM][oO][vV]; do + filesize=$(ls -lah $filename | awk '{ print $5}') + cat >> "$htmlfile" << EOF +$movieicon $filename ($filesize) +EOF + done + echo '
' >> "$htmlfile" +fi + +### Downloads (ZIP) +if [[ $(ls -l | grep -i zip | wc -l) -gt 0 ]]; then + cat >> "$htmlfile" << EOF +
+
+ +
+
+
+
+EOF + for filename in *.[zZ][iI][pP]; do + filesize=$(ls -lah $filename | awk '{ print $5}') + cat >> "$htmlfile" << EOF +$downloadicon $filename ($filesize) +EOF + done + echo '
' >> "$htmlfile" +fi + +### Footer +cat >> "$htmlfile" << EOF +
+
+

$footer

+

$datetime

+
+
+ + +EOF + +debug && echo "= done :-)" \ No newline at end of file -- cgit v1.2.3