-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-images.sh
executable file
·48 lines (40 loc) · 1.17 KB
/
gen-images.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
#!/bin/sh
OPACITY="50%"
SOURCE_DIR="./images"
OUTPUT_DIR="./static"
UPLOAD_DIR="$OUTPUT_DIR/$SOURCE_DIR/uploads"
die () {
[ -n "$1" ] && echo "$1"
exit 1
}
[ -d "$OUTPUT_DIR" ] || mkdir -v "$OUTPUT_DIR"
[ -d "$UPLOAD_DIR" ] || mkdir -v "$UPLOAD_DIR"
for file in $(find "$SOURCE_DIR"); do
if [ -f "$file" ]; then
echo "$file:"
filename="$(basename "$file")"
dirname="$(dirname "$file")"
basename="$(echo "$filename" | sed 's/\(.*\)\.\(.*\)/\1/')"
extension="$(echo "$filename" | sed 's/\(.*\)\.\(.*\)/\2/')"
echo "Creating resized version"
resized="$OUTPUT_DIR/$file"
convert "$file" -resize 'x1080>' "$OUTPUT_DIR/$file" || die
echo "Adding file to uploads"
if [ -f "$UPLOAD_DIR/$filename" ]; then
echo " File already exists"
else
upload="$UPLOAD_DIR/$filename"
cp "$resized" "$upload"
fi
if echo "$dirname" | grep '/headers$' > /dev/null; then
echo "Creating header versions"
light="$OUTPUT_DIR/$dirname/$basename-light.$extension"
convert "$resized" -blur 0x16 -fill white -colorize "$OPACITY" "$light.temp" || die
mv "$light.temp" "$light" || die
fi
echo
elif [ -d "$file" ]; then
mkdir -vp "$OUTPUT_DIR/$file" || die
echo
fi
done