-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathgen_icons.py
More file actions
89 lines (73 loc) · 3.74 KB
/
gen_icons.py
File metadata and controls
89 lines (73 loc) · 3.74 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
import os
import sys
from PIL import Image, ImageDraw
def create_rounded_rect(size, radius, fill_color):
"""Create a rounded rectangle image"""
img = Image.new('RGBA', size, (0, 0, 0, 0))
draw = ImageDraw.Draw(img)
draw.rounded_rectangle([(0, 0), size], radius, fill=fill_color)
return img
def create_circle(size, fill_color):
"""Create a circular image"""
img = Image.new('RGBA', size, (0, 0, 0, 0))
draw = ImageDraw.Draw(img)
draw.ellipse([(0, 0), size], fill=fill_color)
return img
def generate_icons(project_dir):
res_dir = os.path.join(project_dir, 'android', 'app', 'src', 'main', 'res')
foreground_raw_path = os.path.join(res_dir, 'drawable', 'ic_launcher_foreground_raw.png')
if not os.path.exists(foreground_raw_path):
print(f"File not found: {foreground_raw_path}")
return
# Background color is #6C63FF
bg_color = (108, 99, 255, 255)
# Load foreground and crop transparency
fg_img = Image.open(foreground_raw_path).convert("RGBA")
bbox = fg_img.getbbox()
if bbox:
fg_img = fg_img.crop(bbox)
densities = {
'mdpi': 48,
'hdpi': 72,
'xhdpi': 96,
'xxhdpi': 144,
'xxxhdpi': 192
}
for density, size in densities.items():
mipmap_dir = os.path.join(res_dir, f'mipmap-{density}')
os.makedirs(mipmap_dir, exist_ok=True)
# Calculate foreground size (about 75% of total size to allow padding)
# Standard icon is 48dp, safe zone is inner 30dp or so
fg_size = int(size * 0.75)
fg_resized = fg_img.resize((fg_size, fg_size), Image.Resampling.LANCZOS)
# Center coordinate
offset = ((size - fg_size) // 2, (size - fg_size) // 2)
# 1. Square / Rounded Rect icon (ic_launcher.png)
# Android 7 and below standard is rounded rect or square. Let's do rounded rect (radius = size * 0.08)
radius = int(size * 0.08)
square_bg = create_rounded_rect((size, size), radius, bg_color)
square_bg.paste(fg_resized, offset, fg_resized)
square_bg.save(os.path.join(mipmap_dir, 'ic_launcher.png'))
# 2. Round icon (ic_launcher_round.png)
round_bg = create_circle((size, size), bg_color)
round_bg.paste(fg_resized, offset, fg_resized)
round_bg.save(os.path.join(mipmap_dir, 'ic_launcher_round.png'))
# 3. Save a properly scaled foreground PNG to be used directly in adaptive icon
# For adaptive icons, the base size is 108dp. But it's vector-based.
# If we use PNG, it should be 108x108.
# We'll generate a 432x432 (xxxhdpi equivalent for 108dp) transparent foreground
if density == 'xxxhdpi':
adaptive_size = 432
adaptive_fg_size = int(432 * 0.8) # Foreground takes ~80% to fill space well without clipping too much
adaptive_fg_resized = fg_img.resize((adaptive_fg_size, adaptive_fg_size), Image.Resampling.LANCZOS)
adaptive_fg = Image.new('RGBA', (adaptive_size, adaptive_size), (0, 0, 0, 0))
adaptive_offset = ((adaptive_size - adaptive_fg_size) // 2, (adaptive_size - adaptive_fg_size) // 2)
adaptive_fg.paste(adaptive_fg_resized, adaptive_offset, adaptive_fg_resized)
# Save it to drawable-nodpi so we don't need the inset xml
nodpi_dir = os.path.join(res_dir, 'drawable-nodpi')
os.makedirs(nodpi_dir, exist_ok=True)
adaptive_fg.save(os.path.join(nodpi_dir, 'ic_launcher_foreground_adaptive.png'))
print(f"Generated icons for {project_dir}")
if __name__ == '__main__':
generate_icons(r'c:\Users\user\Desktop\app\goose\GooseRelayVPN')
generate_icons(r'C:\Users\user\Desktop\app\goose\masterdns')