-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolution.sh
executable file
·170 lines (158 loc) · 3.54 KB
/
resolution.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
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
#!/bin/bash
RESET='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
is_skins=0
skins_good_res=0
skins_warning_res=0
skins_error_res=0
is_mapres=0
good_res=0
okay_res=0
warning_res=0
error_res=0
error_files=""
if [ "$#" != "1" ] || [ "$1" == "--help" ] || [ "$1" == "-h" ]
then
echo "usage: $(basename "$0") <config file>"
echo "description:"
echo " checks each directory in the config file"
echo " for correct file type (PNG) and resolution (1024x1024)"
echo "sample config:"
echo " # path/to/images type"
echo " foo/tiles tiles"
echo " foo/quads quads"
echo " foo/skins skins"
exit 0
fi
CFG_FILE="$1"
if [ ! -f "$CFG_FILE" ]
then
echo "Error: config file not found '$CFG_FILE'"
exit 1
fi
function check_dir() {
local dir=$1
local arg=$2
local w=0 e=0
local width=0 height=0
echo -n "[*] checking directory '$dir' ($arg) ... "
if [ ! -d "$dir" ]
then
echo ""
echo "Error: directory not found '$dir'"
echo " is your current path and config correct?"
exit 1
fi
for img in "$dir"/*.png
do
[[ -e "$img" ]] || break
meta="$(file -b "$img")"
meta_type="${meta%% *}"
if [ ! "$meta_type" == "PNG" ]
then
echo ""
echo "Error: invalid file type expected 'PNG' got '$meta_type'"
echo " $img"
exit 1
fi
meta_resolution="$(echo "$meta" | cut -d',' -f2 | cut -c 2-)"
if [ "$arg" == "quads" ]
then
is_mapres=1
continue
elif [ "$arg" == "skins" ]
then
is_skins=1
if [ "$meta_resolution" == "256 x 128" ]
then
skins_good_res="$((skins_good_res + 1))"
else
width="$(echo "$meta_resolution" | awk '{print $1}')"
height="$(echo "$meta_resolution" | awk '{print $3}')"
if [ "$width" -lt "256" ] || [ "$((width / 2 ))" != "$height" ]
then
skins_error_res="$((skins_error_res + 1))"
error_files+="${RED}$meta_resolution${RESET} $img\\n"
e=1
else
skins_warning_res="$((skins_warning_res + 1))"
fi
fi
elif [ "$arg" == "tiles" ]
then
is_mapres=1
if [ "$meta_resolution" == "1024 x 1024" ]
then
good_res="$((good_res + 1))"
elif [ "$meta_resolution" == "512 x 512" ]
then
okay_res="$((okay_res + 1))"
w=1
else
width="$(echo "$meta_resolution" | awk '{print $1}')"
height="$(echo "$meta_resolution" | awk '{print $3}')"
if [ "$width" -lt "512" ] || [ "$width" != "$height" ]
then
error_res="$((error_res + 1))"
error_files+="${RED}$meta_resolution${RESET} $img\\n"
e=1
else
warning_res="$((warning_res + 1))"
fi
fi
else
echo "Error: invalid type '$arg'"
exit 1
fi
done
if [ "$e" == "1" ]
then
echo -e "${RED}ERROR"
elif [ "$w" == "1" ]
then
echo -e "${YELLOW}WARNING"
else
echo -e "${GREEN}OK"
fi
echo -en "${RESET}"
}
function show_stats() {
echo -e "$error_files"
echo ""
if [ "$is_mapres" == "1" ]
then
echo "[ mapres ]"
echo "1024 x 1024: $good_res"
echo "512 x 512: $okay_res"
echo "warning: $warning_res"
echo "error: $error_res"
fi
if [ "$is_skins" == "1" ]
then
echo "[ skins ]"
echo "256 x 128: $skins_good_res"
echo "warning: $skins_warning_res"
echo "error: $skins_error_res"
fi
if [ "$error_res" -gt "0" ] || [ "$skins_error_res" -gt "0" ]
then
exit 1
fi
}
while IFS= read -r line
do
if [ "${line:0:1}" == "#" ]
then
continue
fi
if [ "$(echo "$line" | xargs)" == "" ]
then
continue
fi
dir="$(echo "$line" | awk '{print $1}')"
arg="$(echo "$line" | awk '{print $2}')"
check_dir "$dir" "$arg"
done < "$CFG_FILE"
show_stats