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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#!/bin/sh
## Script for generating photo gallery website
##
## Usage:
## $ ./gal [PHOTOS DIR] [OUTPUT DIR]
##
## Setting custom title:
## $ TITLE=Title ./gal [AS ABOVE]
## === Customize ===
QUALITY=70
THUMBNAIL_RESOLUTION=250
RESOLUTION=1500
## =================
PHOTOS=$1
OUTPUT=$2
TITLE=${TITLE:-$(basename $OUTPUT)}
mkdir -p $2/{photos,thumbs}
## Generate index.html menu file
cp style.css $OUTPUT
echo "Generating index.html"
cat > $OUTPUT/index.html <<EOF
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>$TITLE</title>
<link rel="stylesheet" href="style.css" type="text/css" >
</head>
<body>
<h1>$TITLE</h1>
<h3>Last update: $(date '+%d.%m.%Y')</h3>
<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
## Generate photo_list
echo "Generating photo_list"
[ -f $OUTPUT/photo_list ] && echo "Replacing existing photo_list" && rm $OUTPUT/photo_list
for f in $PHOTOS/*.{jpg,JPG,jpeg,JPEG,png,PNG}; do
filename=$(basename $f)
[ -f $f ] && cat >> $OUTPUT/photo_list <<EOF
$filename
EOF
done
## Optimize images
for f in $PHOTOS/*.{jpg,JPG,jpeg,JPEG,png,PNG}; do
filename=$(basename $f)
echo "Optimizing $filename"
[ -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
|