-
Notifications
You must be signed in to change notification settings - Fork 1
/
CXICONMaker.sh
executable file
·142 lines (118 loc) · 2.7 KB
/
CXICONMaker.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
#! /bin/sh
#------------------------------------------------------------------------------
#
# Generates each size image for ICON
#
# Usage: CXICONMaker -i <path> -o <output directory> [-t ios | mac] [-h]
#
# -i path the path of 1024x1024 pixel ICON
# -o path the path of output directory for generated images
# -t type os type, e.g.: ios or mac, default ios
# -h help
#
# Author: chenxing
# Email : chenxing640@foxmail.com
# Date : 2016/3/17
#
#------------------------------------------------------------------------------
help()
{
echo 'sh CXICONMaker.sh -i <path> -o <output directory> [-t ios | mac] [-h]'
echo '-i path the path of 1024x1024 pixel ICON'
echo '-o path the path of output directory for generated images'
echo '-t type os type, e.g.: ios or mac, default ios'
echo '-h help'
exit 1
}
guide()
{
echo 'Error, usage with "cmd -h".'
exit 1
}
osType='ios'
option=':i:o:t:h'
while getopts $option optname
do
case "${optname}" in
'i')
ICONPath=$OPTARG
;;
'o')
outputDir=$OPTARG
;;
't')
osType=$OPTARG
;;
'h')
help
;;
'?')
guide
;;
':')
guide
;;
*)
guide
;;
esac
done
if [ ! "${ICONPath}" -o ! "${outputDir}" ];then
guide
fi
if [ ! -e ${ICONPath} ];then
echo 'Warning: '${ICONPath}' not a valid file.'
exit 2
fi
if [ ! -d ${outputDir} ];then
echo 'Warning: '${outputDir}' not a valid directory.'
exit 3
fi
# 数字部分为ICON尺寸, 新ICON比源ICON尺寸小
# 修改数字即修改ICON尺寸
# MAC
MacAppICONNames=(
"16.png" "32.png"
"64.png" "128.png"
"256.png" "512.png"
)
# IOS
IOSAppICONNames=(
"20.png" "20@2x.png" "20@3x.png"
"29.png" "29@2x.png" "29@3x.png"
"40.png" "40@2x.png" "40@3x.png"
"60@2x.png" "60@3x.png"
"76.png" "76@2x.png"
"83.5@2x.png"
)
AppICONNames=()
if [ ${osType} = 'ios' ];then
AppICONNames=${IOSAppICONNames[@]}
else
AppICONNames=${MacAppICONNames[@]}
fi
sips_cmd='/usr/bin/sips'
function resizeICON()
{
size=$1
name=$2
${sips_cmd} -Z ${size} ${ICONPath} --out ${outputDir}/${name}
}
Prefix='AppIcon'
for ICONName in ${AppICONNames[@]}
do
size=`echo ${ICONName} | awk -F [@~] '{print $1}'`
if [[ ${size} =~ 'png' ]];then
size=${size%.*}
fi
scale=`echo ${ICONName} | awk -F [@~] '{print $2}' | grep -Eo '[0-9]+'`
if [ ! ${scale} ];then
fullsize=$(echo "${size}")
else
fullsize=$(echo "${size} * ${scale}" | bc)
fi
#new_name=${Prefix}'-'${ICONName}
new_name=${Prefix}${size}'x'${ICONName}
echo 'size : '$fullsize' new_name : '$new_name
resizeICON $fullsize $new_name
done