summaryrefslogtreecommitdiffstats
path: root/generate_gallery.sh
blob: 55263836a5ecb53192c452a1941e943705ec2ea8 (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
#!/bin/bash
#----------------------------------------------------
# Version:    0.1.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"
scriptdir="$(dirname "$0")"

html_template="$scriptdir/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
      echo "<div class=\"thumbnail\">" \
           "  <a class=\"thumbnail\" 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"
  popd &>/dev/null
done

rm $tempfile