-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplace_icons.py
More file actions
66 lines (53 loc) · 2.06 KB
/
Copy pathreplace_icons.py
File metadata and controls
66 lines (53 loc) · 2.06 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
import os
from PIL import Image
source_path = r'C:\Users\sungh\.gemini\antigravity\brain\d5b90cff-697f-4b1e-91d4-c8bf4da08094\media__1777918822671.jpg'
res_dir = r'd:\proj\baedalin\app\src\main\res'
# Legacy icon sizes
legacy_sizes = {
'mipmap-xxxhdpi': 192,
'mipmap-xxhdpi': 144,
'mipmap-xhdpi': 96,
'mipmap-hdpi': 72,
'mipmap-mdpi': 48
}
# Adaptive icon foreground sizes (108dp)
adaptive_sizes = {
'mipmap-xxxhdpi': 432,
'mipmap-xxhdpi': 324,
'mipmap-xhdpi': 216,
'mipmap-hdpi': 162,
'mipmap-mdpi': 108
}
img = Image.open(source_path)
# Ensure it's square
width, height = img.size
size = min(width, height)
left = (width - size) / 2
top = (height - size) / 2
right = (width + size) / 2
bottom = (height + size) / 2
img = img.crop((left, top, right, bottom))
for folder, size in legacy_sizes.items():
dest_path = os.path.join(res_dir, folder)
if not os.path.exists(dest_path):
os.makedirs(dest_path)
# Save ic_launcher.png
icon = img.resize((size, size), Image.Resampling.LANCZOS)
icon.save(os.path.join(dest_path, 'ic_launcher.png'))
icon.save(os.path.join(dest_path, 'ic_launcher_round.png'))
for folder, size in adaptive_sizes.items():
dest_path = os.path.join(res_dir, folder)
if not os.path.exists(dest_path):
os.makedirs(dest_path)
# Save ic_launcher_foreground.png
# For adaptive icon, we might want to add some padding so it's not cropped
# The center 66% (72dp out of 108dp) is the safe zone.
# So we resize the image to 72dp and paste it onto a 108dp transparent canvas.
foreground_size = int(size * 0.72) # 72/108 = 0.666, but let's use 72% to be safe
icon_content = img.resize((foreground_size, foreground_size), Image.Resampling.LANCZOS)
# Create transparent background
foreground = Image.new('RGBA', (size, size), (0, 0, 0, 0))
offset = (size - foreground_size) // 2
foreground.paste(icon_content, (offset, offset))
foreground.save(os.path.join(dest_path, 'ic_launcher_foreground.png'))
print("Icons replaced successfully.")