about summary refs log tree commit diff
path: root/gal
blob: 3ceaa138a5ced3c16f0a8a07b06b66ccaf1ed7d4 (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
55
56
57
58
59
60
61
62
63
#!/bin/sh
## Script for generating photo gallery website
##
## Usage:
## $ ./gal [PHOTOS DIR] [OUTPUT DIR]

## === Customize ===

QUALITY=70
THUMBNAIL_RESOLUTION=250
RESOLUTION=1500

## =================


PHOTOS=$1
OUTPUT=$2
mkdir -p $2/{photos,thumbs}

## Generate index.html menu file
cp style.css $OUTPUT

cat > $OUTPUT/index.html <<EOF
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>Gallery</title>
    <link rel="stylesheet" href="style.css" type="text/css" >
  </head>
  <body>
    <div class="tiles">
EOF


for f in $PHOTOS/*.{jpg,JPG,jpeg,JPEG,png,PNG}; do
  filename=$(basename $f)
  [ -f $f ] && cat >> $OUTPUT/index.html <<EOF
      <div class="tile">
        <a href="photos/$filename">
          <img src="thumbs/$filename" alt="$filename" />
        </a>
      </div>
EOF
done

cat >> $OUTPUT/index.html <<EOF
    </div>
    <footer>
      <p>This page is <a href="https://jeffhuang.com/designed_to_last/">designed to last</a>.</p>
    </footer>
  </body>
</html>
EOF

## Optimize images

for f in $PHOTOS/*.{jpg,JPG,jpeg,JPEG,png,PNG}; do
  filename=$(basename $f)
  [ -f $f ] && convert -auto-orient -strip -quality $QUALITY -resize x$RESOLUTION "$f" "$OUTPUT/photos/$filename" && \
    convert -auto-orient -strip -quality $QUALITY -resize x$THUMBNAIL_RESOLUTION "$f" "$OUTPUT/thumbs/$filename"
done