-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgen_android_icons.sh
More file actions
executable file
·48 lines (38 loc) · 1.85 KB
/
gen_android_icons.sh
File metadata and controls
executable file
·48 lines (38 loc) · 1.85 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
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
command -v rsvg-convert >/dev/null 2>&1 || { echo "Error: rsvg-convert not found. Install librsvg (e.g. pacman -S librsvg)."; exit 1; }
command -v magick >/dev/null 2>&1 || { echo "Error: magick not found. Install imagemagick."; exit 1; }
for f in "app icon.svg" "app icon without border.svg" "app icon monochrome.svg" "app icon background.svg"; do
[[ -f "$f" ]] || { echo "Error: source file missing: $f"; exit 1; }
done
RES=android/app/src/main/res
# density -> (launcher_size, adaptive_size)
declare -A LAUNCHER_SIZE=( [mdpi]=48 [hdpi]=72 [xhdpi]=96 [xxhdpi]=144 [xxxhdpi]=192 )
declare -A ADAPTIVE_SIZE=( [mdpi]=108 [hdpi]=162 [xhdpi]=216 [xxhdpi]=324 [xxxhdpi]=432 )
svg_to_png() {
local src="$1" size="$2" dst="$3"
rsvg-convert -w "$size" -h "$size" "$src" -o "$dst"
echo " -> $dst ($size x $size)"
}
# Adaptive icon layers must fill 108dp total. Scale SVG to 19/42 of target
# (19/28 of the 72dp safe zone), then pad to full size.
svg_to_adaptive_png() {
local src="$1" size="$2" dst="$3"
local safe=$(( size * 19 / 42 ))
# local safe=$(( size * 2 / 3 ))
rsvg-convert -w "$safe" -h "$safe" "$src" \
| magick - -gravity center -background transparent -extent "${size}x${size}" "$dst"
echo " -> $dst (${size}x${size}, artwork ${safe}x${safe})"
}
for density in mdpi hdpi xhdpi xxhdpi xxxhdpi; do
dir="$RES/mipmap-$density"
ls_size=${LAUNCHER_SIZE[$density]}
ad_size=${ADAPTIVE_SIZE[$density]}
echo "$density:"
svg_to_png "app icon.svg" "$ls_size" "$dir/ic_launcher.png"
svg_to_png "app icon background.svg" "$ad_size" "$dir/ic_launcher_background.png"
svg_to_adaptive_png "app icon without border.svg" "$ad_size" "$dir/ic_launcher_foreground.png"
svg_to_png "app icon monochrome.svg" "$ad_size" "$dir/ic_launcher_monochrome.png"
done
echo "Done."