-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.sh
executable file
·69 lines (62 loc) · 1.22 KB
/
convert.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
#!/bin/bash
set -eu
cd "$(dirname "$0")"
sizes=(22 48 128)
weathers=(
cloud
fog
lightcloud
lightrain
lightrainsun
lightrainthunder
lightrainthundersun
nodata
partlycloud
rain
rainthunder
sleet
sleetsun
sleetsunthunder
sleetthunder
snow
snowsun
snowsunthunder
snowthunder
sun
)
icons=("$@")
if [[ ${#icons[@]} -eq 0 ]]; then
for weather in ${weathers[@]}; do
icons+=("$weather" "$weather-night")
done
fi
convert_icon () {
icon=$1
icon_src="svg/$icon.svg"
if [[ ! -e $icon_src ]]; then
echo "$icon_src: no such file" >&2
return 1
fi
for size in ${sizes[@]}; do
size_src="svg/$icon.$size.svg"
if [[ ! -e $size_src ]]; then
size_src=$icon_src
fi
dest="$size/$icon.png"
(
convert -resize "${size}x${size}" -background none +set date:create +set date:modify "$size_src" "$dest"
echo "$size_src: wrote $dest"
) &
done
}
converted=0
for icon in "${icons[@]}"; do
if convert_icon "$icon"; then
converted=$((converted + 1))
fi
done
wait
if [[ $converted -eq 0 ]]; then
echo "no icons converted!" >&2
exit 1
fi