blob: 7e66605eb00bef418ec5604e06e32c261b7ae0e6 (
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
#!/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</title>
<meta name="viewport" content="width=device-width">
<meta name="robots" content="noindex, nofollow">
<link rel="stylesheet" href="$stylesheet">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-12">
<div class="page-header"><h1>$title</h1></div>
</div>
</div>
EOF
### Photos (JPG)
if [[ $(ls -l | grep -i jpg | wc -l) -gt 0 ]]; then
echo '<div class="row">' >> "$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
<div class="col-md-3 col-sm-12">
<p>
<a href="$thumbdir/$filename.html"><img src="$thumbdir/$height_small/$filename" alt="" class="img-responsive"></a>
<div class="hidden-md hidden-lg"><hr></div>
</p>
</div>
EOF
[[ $(( $numfiles % 4 )) -eq 0 ]] && echo '<div class="clearfix visible-md visible-lg"></div>' >> "$htmlfile"
done
echo '</div>' >> "$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
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title>$filename</title>
<meta name="viewport" content="width=device-width">
<meta name="robots" content="noindex, nofollow">
<link rel="stylesheet" href="$stylesheet">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-12">
<div class="page-header"><h2><a href="../$htmlfile">$homeicon</a> <span class="text-muted">/</span> $filename</h2></div>
</div>
</div>
EOF
# Pager
echo '<div class="row"><div class="col-xs-12"><nav><ul class="pager">' >> "$imagehtmlfile"
[[ $prev ]] && echo '<li class="previous"><a href="'$prev'.html"><span aria-hidden="true">←</span></a></li>' >> "$imagehtmlfile"
[[ $next ]] && echo '<li class="next"><a href="'$next'.html"><span aria-hidden="true">→</span></a></li>' >> "$imagehtmlfile"
echo '</ul></nav></div></div>' >> "$imagehtmlfile"
cat >> "$imagehtmlfile" << EOF
<div class="row">
<div class="col-xs-12">
<p><img src="$height_large/$filename" class="img-responsive" alt=""></p>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<p><a class="btn btn-info btn-lg" href="../$filename">$downloadicon Download Original Image File ($filesize)</a></p>
</div>
</div>
EOF
# EXIF
if [[ $exifinfo ]]; then
cat >> "$imagehtmlfile" << EOF
<div class="row">
<div class="col-xs-12">
<pre>
$exifinfo
</pre>
</div>
</div>
EOF
fi
# Footer
cat >> "$imagehtmlfile" << EOF
</div>
</body>
</html>
EOF
let file++
done
fi
### Movies (MOV or MP4)
if [[ $(ls -l | grep -i "mov\|mp4" | wc -l) -gt 0 ]]; then
cat >> "$htmlfile" << EOF
<div class="row">
<div class="col-xs-12">
<div class="page-header"><h2>Movies</h2></div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
EOF
if [[ $(ls -l | grep -i "mov" | wc -l) -gt 0 ]]; then
for filename in *.[mM][oO][vV]; do
filesize=$(ls -lah "$filename" | awk '{ print $5}')
cat >> "$htmlfile" << EOF
<a href="$filename" class="btn btn-primary" role="button">$movieicon $filename ($filesize)</a>
EOF
done
fi
if [[ $(ls -l | grep -i "mp4" | wc -l) -gt 0 ]]; then
for filename in *.[mM][pP]4; do
filesize=$(ls -lah "$filename" | awk '{ print $5}')
cat >> "$htmlfile" << EOF
<a href="$filename" class="btn btn-primary" role="button">$movieicon $filename ($filesize)</a>
EOF
done
fi
echo '</div></div>' >> "$htmlfile"
fi
### Downloads (ZIP)
if [[ $(ls -l | grep -i zip | wc -l) -gt 0 ]]; then
cat >> "$htmlfile" << EOF
<div class="row">
<div class="col-xs-12">
<div class="page-header"><h2>Downloads</h2></div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
EOF
for filename in *.[zZ][iI][pP]; do
filesize=$(ls -lah "$filename" | awk '{ print $5}')
cat >> "$htmlfile" << EOF
<a href="$filename" class="btn btn-primary" role="button">$downloadicon $filename ($filesize)</a>
EOF
done
echo '</div></div>' >> "$htmlfile"
fi
### Footer
cat >> "$htmlfile" << EOF
<hr>
<footer>
<p>$footer</p>
<p class="text-muted">$datetime</p>
</footer>
</div> <!-- // container -->
</body>
</html>
EOF
debug && echo "= done :-)"
|