forked from tokee/juxta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_multi.sh
executable file
·99 lines (89 loc) · 2.87 KB
/
demo_multi.sh
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
#!/bin/bash
# Displays multiple collections as one large gallery with each collection being show below
# the previous one. The effect is achieved by inserting blank images.
: ${BACKGROUND:="000000"}
: ${AGGRESSIVE_IMAGE_SKIP:=true}
: ${ALLOW_UPSCALE:=true}
# If true, the generated index.html will be put one level above the destination folder
: ${MOVE_INDEX_UP:=false}
: ${MAX_SOURCES:=9999999} # Equivalent to MAX_IMAGES, but for sources
: ${MAX_IMAGES:=9999999} # Why do we need this here?
pushd ${BASH_SOURCE%/*} > /dev/null
JUXTA_HOME=$(pwd)
popd > /dev/null
: ${TEMPLATE:="$JUXTA_HOME/demo_multi.template.html"}
usage() {
echo "Usage:"
echo "./demo_multi.sh imagefile* destination"
echo "It is highly recommended to specify RAW_IMAGE_COLS."
exit $1
}
# Resolve sources and destination
if [ "$#" -lt "2" ]; then
>&2 echo "Error: Need at least 1 source and a destination"
usage 2
fi
# Check source & destination
SOURCES=""
SCOUNT=0
for ARG in "$@"; do
SCOUNT=$((SCOUNT+1))
if [[ "$SCOUNT" -eq "$#" ]]; then
DEST="$ARG"
break
fi
if [[ "$SCOUNT" -gt "$MAX_SOURCES" ]]; then
continue
fi
if [[ ! -f "$ARG" ]]; then
>&2 echo "Error: Source file '$ARG' cannot be read"
usage 3
fi
if [[ "." != ".$SOURCES" ]]; then
SOURCES="$SOURCES"$'\n'
fi
SOURCES="$SOURCES$ARG"
done
# Check dimensions
TOTAL_IMAGES=$(cat $SOURCES | wc -l)
if [[ ".$RAW_IMAGE_COLS" == "." ]]; then
RAW_IMAGE_COLS=$(echo "sqrt($TOTAL_IMAGES)" | bc)
echo "Warning: RAW_IMAGE_COLS not specified. Setting RAW_IMAGE_COLS to sqrt($TOTAL_IMAGES images)=$RAW_IMAGE_COLS "
fi
echo "Montaging $(wc -l <<< "$SOURCES") image sources containing a total of $TOTAL_IMAGES images"
# Create merged source file with blanks inserted to get visual grouping
mkdir -p "$DEST/resources"
rm -f "$DEST/multi_source.dat"
echo "var groups = { elements: [" > "$DEST/resources/groups.js"
ROW=0 # Only used when debugging. Consider removal
while read -r SOURCE; do
COL=0
while read -r IMG; do
if [[ $COL -eq 0 ]]; then
#echo "$ROW $SOURCE"
echo "\"${SOURCE}\"," >> "$DEST/resources/groups.js"
fi
COL=$((COL+1))
echo "$IMG" >> "$DEST/multi_source.dat"
if [[ "$COL" -eq "$RAW_IMAGE_COLS" ]]; then
ROW=$((ROW+1))
COL=0
fi
done < $SOURCE
if [[ $COL -gt 0 ]]; then
ROW=$((ROW+1))
fi
while [[ "$COL" -ne 0 && "$COL" -lt "$RAW_IMAGE_COLS" ]]; do
echo "missing" >> "$DEST/multi_source.dat"
COL=$((COL+1))
done
done <<< "$SOURCES"
echo "]}" >> "$DEST/resources/groups.js"
# Ensure that index can be moves if needed
if [[ "$MOVE_INDEX_UP" == "true" ]]; then
DATA_ROOT="${DEST%/}/"
fi
. $JUXTA_HOME/juxta.sh "$DEST/multi_source.dat" "$DEST"
if [[ "$MOVE_INDEX_UP" == "true" ]]; then
mv "$DEST/index.html" $(dirname "$DEST")
fi