summaryrefslogtreecommitdiffstats
path: root/generate_gallery.sh
blob: 6efed9288da2132e97402276b6e628da5f2563db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
#----------------------------------------------------
# Version:		0.3.0
# Author:				Florian "Bluewind" Pritz <flo@xssn.at>
#
# Licensed under WTFPL v2
# (see COPYING for full license text)
#
#----------------------------------------------------
# put images in folder "foo" and run "$0 foo" 
#----------------------------------------------------

startdir="$PWD"
datadir="$(dirname "$0")/generate_gallery.d"

html_template="$datadir/template.html"

tempfile=$(mktemp "/tmp/image-gallery.XXXXXX")

for i in "$@"; do
	pushd "$i" &>/dev/null
	echo > $tempfile
	for img in *; do
		filename="$(basename "$img")"
		pushd "$(dirname "$img")" &>/dev/null
		mkdir -p thumbs
		if file -b --mime-type "$img" | grep -q "image/.*"; then
			if [ ! -e "thumbs/$filename" ]; then
				echo "processing: $i/$img"
				convert "$filename" -thumbnail 200x200 "thumbs/$filename"
			fi
			fnumber=$(exiftool -s -s -s -FNumber $filename)
			focallength=$(exiftool -s -s -s -FocalLength $filename)
			shutterspeed=$(exiftool -s -s -s -ShutterSpeed $filename)
			echo "<div class=\"thumbnail\">" \
							"<a rel=\"images\" class=\"thumbnail\" title=\"${shutterspeed}s, $focallength @ F $fnumber\" href=\"$img\">" \
							"<img class=\"thumbnail\" alt=\"\" src=\"thumbs/$img\" />" \
							"</a>" \
					 "</div>" | sed -r 's/\/\//\//g' >> $tempfile
		else
			echo "ignoring non-image: $i/$img"
		fi
		popd &>/dev/null
	done
	cd "$startdir"
	sed -r \
		-e "/%%CONTENT%%/r $tempfile" \
		-e '/%%CONTENT/d' \
		"$html_template" > "$i/index.html"
	cp -r "$datadir/fancybox" "$i"
	popd &>/dev/null
done

rm $tempfile