-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathandroid-generator.sh
More file actions
executable file
·168 lines (133 loc) · 4.09 KB
/
android-generator.sh
File metadata and controls
executable file
·168 lines (133 loc) · 4.09 KB
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
#!/bin/sh
###################################
#
# App Icon Generator v0.0.2
#
# Andrey A. Ugolnik
# https://www.ugolnik.info
# andrey@ugolnik.info
#
###################################
SRC_ICON="$1"
SRC_BANNER="$2"
DST_PATH="$3"
info() {
local green="\033[1;32m"
local normal="\033[0m"
echo "[${green}INFO${normal}] $1"
}
error() {
local red="\033[1;31m"
local normal="\033[0m"
echo "[${red}ERROR${normal}] $1"
}
usage() {
cat <<EOF
USAGE:
$0 SourceIcon SourceBanner DestPath
DESCRIPTION:
This script aim to generate Android TV app icons easier and simply.
SourceIcon - The source png Icon. Preferably above 1024x1024.
SourceBanner - The source png Banner. Preferably above 1280x720.
DestPath - The destination Path where the icons and banners generate to.
This script is depend on ImageMagick. So you must install ImageMagick first
You can use 'brew install ImageMagick' to install it
EXAMPLE:
$0 Banner.png Icon.png Output/
EOF
}
# Check ImageMagick
command -v magick >/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
makeIconTV() {
local LOUTPATH="$DST_PATH/$1"
local LSIZE="$2"
# make destination path
mkdir -p "$LOUTPATH"
# make rect icon
magick "$SRC_ICON" -resize $LSIZE! "$LOUTPATH/ic_launcher.png"
}
makeIconTV "mipmap-mdpi" "80x80"
makeIconTV "mipmap-hdpi" "120x120"
makeIconTV "mipmap-xhdpi" "160x160"
makeIconTV "mipmap-xxhdpi" "240x240"
makeIconTV "mipmap-xxxhdpi" "320x320"
info 'Android TV icons ready.'
makeBannerTV() {
local LOUTPATH="$DST_PATH/$1"
local LSIZE="$2"
# make destination path
mkdir -p "$LOUTPATH"
# make rect icon
magick "$SRC_BANNER" -resize $LSIZE! "$LOUTPATH/ic_banner.png"
}
makeBannerTV "mipmap-mdpi" "160x90"
makeBannerTV "mipmap-hdpi" "240x135"
makeBannerTV "mipmap-xhdpi" "320x180"
makeBannerTV "mipmap-xxhdpi" "480x270"
makeBannerTV "mipmap-xxxhdpi" "640x360"
info 'Android TV banners ready.'
makeIcon() {
local LOUTPATH="$DST_PATH/$1"
local LSIZE="$2"
# make destination path
mkdir -p "$LOUTPATH"
# make rect icon
magick "$SRC_ICON" -resize $LSIZE! "$LOUTPATH/ic_launcher.png"
# make rect foreground icon
if [ $# -ge 4 ]; then
local FSIZE="$3"
local ESIZE="$4"
magick "$SRC_ICON" -resize $FSIZE^ -gravity center -background none -extent $ESIZE "$LOUTPATH/ic_launcher_foreground.png"
fi
# make rounded icon
magick "$LOUTPATH/ic_launcher.png" \( +clone -threshold 101% -fill white -draw 'circle %[fx:int(w/2)],%[fx:int(h/2)] %[fx:int(w/2)],1' \) -channel-fx '| gray=>alpha' "$LOUTPATH/ic_launcher_round.png"
}
makeAnyDpi() {
local XMLPATH="$1"
local ANYDPIPATH="$DST_PATH/mipmap-anydpi-v26"
# make destination path
mkdir -p "$ANYDPIPATH"
# write adaptive icon xml
cat <<EOF >"$ANYDPIPATH/$XMLPATH.xml"
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
EOF
}
makeBackground() {
local XMLPATH="$1"
local ANYDPIPATH="$DST_PATH/colors"
# make destination path
mkdir -p "$ANYDPIPATH"
# write adaptive icon xml
cat <<EOF >"$ANYDPIPATH/$XMLPATH.xml"
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#000000</color>
</resources>
EOF
}
makeIcon "mipmap-mdpi" "48x48" "66x66" "108x108"
makeIcon "mipmap-hdpi" "72x72" "99x99" "162x162"
makeIcon "mipmap-xhdpi" "96x96" "132x132" "216x216"
makeIcon "mipmap-xxhdpi" "144x144" "198x198" "324x324"
makeIcon "mipmap-xxxhdpi" "192x192" "264x264" "432x432"
makeAnyDpi "ic_launcher"
makeAnyDpi "ic_launcher_round"
makeBackground "ic_launcher_background"
info 'Android icons ready.'
cat <<EOF
Add the following lines to your AndroidManifest.xml inside the <application> tag:
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
EOF