forked from smallmuou/ios-icon-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ios-custom-icon-generator.sh
executable file
·103 lines (84 loc) · 3.14 KB
/
ios-custom-icon-generator.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
#!/bin/bash
#
# Copyright (C) 2015 Alessandro Miliucci<[email protected]>
#
# Based on https://github.com/smallmuou/ios-icon-generator/blob/master/ios-icon-generator.sh
# from Wenva <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is furnished
# to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
set -e
SRC_FILE="$1"
DST_PATH="$2"
SIZE="$3"
VERSION=1.0.0
info() {
local green="\033[1;32m"
local normal="\033[0m"
echo -e "[${green}INFO${normal}] $1"
}
error() {
local red="\033[1;31m"
local normal="\033[0m"
echo -e "[${red}ERROR${normal}] $1"
}
usage() {
cat << EOF
VERSION: $VERSION
USAGE:
$0 srcfile dstpath size
DESCRIPTION:
This script aim to generate ios navigation icons easier and simply.
srcfile - The source png image. Preferably big.
dstpath - The destination path where the icons generate to.
size - The destination size in pixel, only one number (e.g 60)
This script is depend on ImageMagick. So you must install ImageMagick first
You can use 'sudo brew install ImageMagick' to install it
AUTHOR:
Alessandro Miliucci<[email protected]>
LICENSE:
This script follow MIT license.
EXAMPLE:
$0 icon-big.png ~/asset_dir 100
EOF
}
# Check ImageMagick
command -v convert >/dev/null 2>&1 || { error >&2 "The ImageMagick is not installed. Please use brew to install it first."; exit -1; }
# Check param
if [ $# != 3 ];then
usage
exit -1
fi
# Check dst path whether exist.
if [ ! -d "$DST_PATH" ];then
mkdir -p "$DST_PATH"
fi
# Generate, refer to:https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/IconMatrix.html#//apple_ref/doc/uid/TP40006556-CH27-SW2
FILENAME=$(basename "$SRC_FILE")
#extension="${filename##*.}"
FILENAME="${FILENAME%.*}"
OUT_FILENAME="$FILENAME.png"
info "Generate $FILENAME.png ..."
convert "$SRC_FILE" -resize "$SIZE"x"$SIZE" "$DST_PATH/$FILENAME.png"
info "Generate [email protected] ..."
DOUBLE_SIZE=$(($SIZE * 2))
convert "$SRC_FILE" -resize "$DOUBLE_SIZE"x"$DOUBLE_SIZE" "$DST_PATH/[email protected]"
TRIPLE_SIZE=$(($SIZE * 3))
info "Generate [email protected] ..."
convert "$SRC_FILE" -resize "$TRIPLE_SIZE"x"$TRIPLE_SIZE" "$DST_PATH/[email protected]"
info 'Generate Done.'