-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconvert-images.sh
executable file
·54 lines (44 loc) · 1.21 KB
/
convert-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
49
50
51
52
53
54
#!/bin/bash
set -e
dirfilter="---"
while [[ $# -gt 0 ]]; do
key="$1"
shift
case "$key" in
"--dir"|"--dirs")
dirfilter="$1"
shift
;;
*)
echo "Unknown argument '$key'"
exit 1
;;
esac
done
for conversion in $(cat image-conversions.conf); do
if [ $(echo "$conversion" | cut -c1) != "#" ]; then
scope=$(echo "$conversion" | cut -d: -f1 -)
original=$(echo "$conversion" | cut -d: -f2 -)
destination=$(echo "$conversion" | cut -d: -f3 -)
size=$(echo "$conversion" | cut -d: -f4 -)
echo "Converting $scope::$original"
if [[ dirfilter != "---" ]]; then
found="no"
for d in $dirfilter; do
if [[ "$scope" == "$d" ]]; then
found="yes"
fi
done
if [[ "$found" == "no" ]]; then
continue
fi
fi
for f in source/$scope/$original; do
filename=$(basename "$f")
filebase="${filename%.*}"
destfile="source/$scope/$destination$filebase.png"
echo " $f => $destfile"
convert $f -resize $size -background transparent -gravity center -extent $size $destfile
done
fi
done