-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_1x2x3x.sh
executable file
·41 lines (29 loc) · 1.3 KB
/
script_1x2x3x.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
for f in *.png
do
# Process to get File Name & 2x, 3x file names
xNAME=`echo "$f" | cut -d'.' -f1`
cp "$f" "$xNAME@3x.png"
cp "$f" "$xNAME@2x.png"
# Set proper resolution to original file
sips -s dpiHeight 72.0 -s dpiWidth 72.0 "$f"
# Get Width of original file
xWIDTH=`sips -g pixelWidth "$f" | cut -d':' -f 2 | tail -1 | cut -d' ' -f 2`
# Get Height of original file
xHEIGHT=`sips -g pixelHeight "$f" | cut -d':' -f 2 | tail -1 | cut -d' ' -f 2`
# Variables for 1x
xWIDTH1=`expr $xWIDTH / 3`
xHEIGHT1=`expr $xHEIGHT / 3`
# Variables for 2x
xWIDTH2=`expr $xWIDTH1 \* 2`
xHEIGHT2=`expr $xHEIGHT1 \* 2`
# Applying size to all three images
sips -z "$xHEIGHT1" "$xWIDTH1" "$f"
sips -z "$xHEIGHT2" "$xWIDTH2" "$xNAME@2x.png"
# Creating Asset folder & moving images into asset folder
mkdir "$xNAME.imageset"
mv "$f" "$xNAME.imageset/"
mv "$xNAME@2x.png" "$xNAME.imageset/"
mv "$xNAME@3x.png" "$xNAME.imageset/"
echo "{ \"images\" : [ { \"idiom\" : \"universal\", \"filename\" : \"$f\", \"scale\" : \"1x\" }, { \"idiom\" : \"universal\", \"filename\" : \"$xNAME@2x.png\", \"scale\" : \"2x\" }, { \"idiom\" : \"universal\", \"filename\" : \"$xNAME@3x.png\", \"scale\" : \"3x\" } ], \"info\" : { \"version\" : 1, \"author\" : \"xcode\" } }" > Contents.json
mv Contents.json "$xNAME.imageset/"
done