-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathios_resizer
executable file
·225 lines (192 loc) · 7.87 KB
/
ios_resizer
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/bin/bash
CUR_DIR="$PWD"
IFS=$'\n';
function to2x(){
for f in $( find $CUR_DIR -iname "*.png" -or -iname "*.jpg" ); do
if [[ $f == *"@3x"* ]]
then
image_dir=$(dirname $f)
image_name=$(basename $f)
extension="${image_name##*.}"
filename="${image_name%.*}"
newnamex2=${filename/@3x/@2x}
newnamex1=${filename/@3x/""}
newfilex2="$image_dir/$newnamex2.$extension"
newfilex1="$image_dir/$newnamex1.$extension"
echo "Procesing: $f > $newfilex1 ";
$(convert $f -resize 66.6% $newfilex2)
$(convert $f -resize 33.3% $newfilex1)
fi
done
}
function to1x(){
for f in $( find $CUR_DIR -iname "*.png" -or -iname "*.jpg" ); do
if [[ $f == *"@2x"* ]]
then
image_dir=$(dirname $f)
image_name=$(basename $f)
extension="${image_name##*.}"
filename="${image_name%.*}"
newnamex1=${filename/@2x/""}
newfilex1="$image_dir/$newnamex1.$extension"
echo "Procesing: $f > $newfilex1 ";
$(convert $f -resize 50% $newfilex1)
fi
done
}
function createAppIcon(){
image=$1;
assetsFolder=$2
if [[ -z "$assetsFolder" ]]; then
echo "Error please sepcify Assets folder"
return
fi
xcassets="$CUR_DIR/$assetsFolder/AppIcon.appiconset/Contents.json"
if [ -f $image ]; then
echo "Resizing app icon"
if [ -f $xcassets ]; then
echo "Found $assetsFolder/AppIcon.appiconset/Contents.json"
icon29="icon-29.png"
icon58="icon-58.png"
icon80="icon-80.png"
icon120="icon-120.png"
icon180="icon-180.png"
icon40="icon-40.png"
icon80="icon-80.png"
icon76="icon-76.png"
icon152="icon-152.png"
icon87="icon-87.png"
$(convert $image -resize 29x29 $assetsFolder/AppIcon.appiconset/$icon29)
$(convert $image -resize 58x58 $assetsFolder/AppIcon.appiconset/$icon58)
$(convert $image -resize 80x80 $assetsFolder/AppIcon.appiconset/$icon80)
$(convert $image -resize 40x40 $assetsFolder/AppIcon.appiconset/$icon40)
$(convert $image -resize 80x80 $assetsFolder/AppIcon.appiconset/$icon80)
$(convert $image -resize 76x76 $assetsFolder/AppIcon.appiconset/$icon76)
$(convert $image -resize 87x87 $assetsFolder/AppIcon.appiconset/$icon87)
$(convert $image -resize 152x152 $assetsFolder/AppIcon.appiconset/$icon152)
$(convert $image -resize 120x120 $assetsFolder/AppIcon.appiconset/$icon120)
$(convert $image -resize 180x180 $assetsFolder/AppIcon.appiconset/$icon180)
appIconJson="{
\"images\" : [
{
\"size\" : \"29x29\",
\"idiom\" : \"iphone\",
\"filename\" : \"$icon58\",
\"scale\" : \"2x\"
},
{
\"size\" : \"29x29\",
\"idiom\" : \"iphone\",
\"filename\" : \"$icon87\",
\"scale\" : \"3x\"
},
{
\"size\" : \"40x40\",
\"idiom\" : \"iphone\",
\"filename\" : \"$icon80\",
\"scale\" : \"2x\"
},
{
\"size\" : \"40x40\",
\"idiom\" : \"iphone\",
\"filename\" : \"$icon120\",
\"scale\" : \"3x\"
},
{
\"size\" : \"60x60\",
\"idiom\" : \"iphone\",
\"filename\" : \"$icon120\",
\"scale\" : \"2x\"
},
{
\"size\" : \"60x60\",
\"idiom\" : \"iphone\",
\"filename\" : \"$icon180\",
\"scale\" : \"3x\"
},
{
\"idiom\" : \"ipad\",
\"size\" : \"29x29\",
\"filename\" : \"$icon29\",
\"scale\" : \"1x\"
},
{
\"size\" : \"29x29\",
\"idiom\" : \"ipad\",
\"filename\" : \"$icon58\",
\"scale\" : \"2x\"
},
{
\"idiom\" : \"ipad\",
\"size\" : \"40x40\",
\"filename\" : \"$icon40\",
\"scale\" : \"1x\"
},
{
\"size\" : \"40x40\",
\"idiom\" : \"ipad\",
\"filename\" : \"$icon80\",
\"scale\" : \"2x\"
},
{
\"size\" : \"76x76\",
\"idiom\" : \"ipad\",
\"filename\" : \"$icon76\",
\"scale\" : \"1x\"
},
{
\"size\" : \"76x76\",
\"idiom\" : \"ipad\",
\"filename\" : \"$icon152\",
\"scale\" : \"2x\"
}
],
\"info\" : {
\"version\" : 1,
\"author\" : \"xcode\"
}
}"
echo $appIconJson > $xcassets
echo "Finished generating app icons"
else
echo "Can't find $assetsFolder/AppIcon.appiconset/Contents.json to proceed"
echo "Please make sure that you are in your project folder"
fi
else
echo "Please specify a valid app icon location"
fi
}
function createSplashImage(){
echo "Creating splash image"
$orinetation=$1
echo "$1"
echo "$2"
}
function usage(){
echo "usage ./ios_resizer [to2x | to3x | --help]"
}
function help(){
echo "This script depends on imagemagic program"
echo "To install imagemagic please run"
echo "brew install imagemagick"
echo "And make sure to put imagemagick in your path"
echo ""
echo "iresize to2x - Convert all @x3 photos to @2x photos, and normal photo for non retina"
echo "iresize to1x - Convert all @x2 photos to normal photo for non retina"
echo "iresize [-ai] <file> <assetsFolder> - App-Icon - Create app icon from specified <file> image, note that you must be"
echo " inside folder where your Assets folder resides. <assetsFolder> is absolute path to you assets folder"
echo " Make sure that icon is at least 180x180px and png format for best results."
}
if [[ $1 == "to2x" ]]; then
to2x
elif [[ $1 == "to1x" ]]; then
to1x
elif [[ $1 == "--help" ]]; then
help
elif [[ $1 == "-ai" ]]; then
createAppIcon $2 $3
elif [[ $1 == "-li" ]]; then
createSplashImage $2 $3
else
usage
fi