115 lines
4.7 KiB
Python
115 lines
4.7 KiB
Python
import os
|
|
from PIL import Image, ImageDraw
|
|
|
|
SRC_IMAGE = '/home/alexives/.gemini/antigravity-ide/brain/4ff924d9-3d7f-4202-9066-3ac5c3088b8e/star_13_no_horizontal_line_clean.png'
|
|
src = Image.open(SRC_IMAGE).convert('RGBA')
|
|
|
|
# 1. Update Assets & Masters
|
|
src.resize((1024, 1024), Image.Resampling.LANCZOS).save('assets/icons/app_icon_1024.png', 'PNG')
|
|
src.resize((512, 512), Image.Resampling.LANCZOS).save('assets/icons/app_icon_512.png', 'PNG')
|
|
src.resize((512, 512), Image.Resampling.LANCZOS).save('scripts/app_icon_master.png', 'PNG')
|
|
|
|
# 2. Android Mipmaps (Legacy + Adaptive Icon support)
|
|
# Sizes for legacy (48, 72, 96, 144, 192)
|
|
# Sizes for adaptive 108dp (108, 162, 216, 324, 432)
|
|
densities = {
|
|
'android/app/src/main/res/mipmap-mdpi': (48, 108),
|
|
'android/app/src/main/res/mipmap-hdpi': (72, 162),
|
|
'android/app/src/main/res/mipmap-xhdpi': (96, 216),
|
|
'android/app/src/main/res/mipmap-xxhdpi': (144, 324),
|
|
'android/app/src/main/res/mipmap-xxxhdpi': (192, 432),
|
|
}
|
|
|
|
# Create foreground (scaled to 72% safe zone on transparent background)
|
|
def make_adaptive_foreground(size):
|
|
fg = Image.new('RGBA', (size, size), (0, 0, 0, 0))
|
|
# Scale emblem to 72% of canvas so it never clips in circle/squircle masks
|
|
inner_sz = int(size * 0.72)
|
|
emblem = src.resize((inner_sz, inner_sz), Image.Resampling.LANCZOS)
|
|
offset = (size - inner_sz) // 2
|
|
fg.paste(emblem, (offset, offset), emblem)
|
|
return fg
|
|
|
|
# Create background (full bleed cosmos)
|
|
def make_adaptive_background(size):
|
|
return src.resize((size, size), Image.Resampling.LANCZOS)
|
|
|
|
for folder, (sz_legacy, sz_adapt) in densities.items():
|
|
os.makedirs(folder, exist_ok=True)
|
|
|
|
# 1. Legacy square
|
|
resized = src.resize((sz_legacy, sz_legacy), Image.Resampling.LANCZOS)
|
|
resized.save(os.path.join(folder, 'ic_launcher.png'), 'PNG')
|
|
|
|
# 2. Legacy round
|
|
mask = Image.new('L', (sz_legacy, sz_legacy), 0)
|
|
draw = ImageDraw.Draw(mask)
|
|
draw.ellipse((0, 0, sz_legacy, sz_legacy), fill=255)
|
|
round_img = Image.new('RGBA', (sz_legacy, sz_legacy), (0, 0, 0, 0))
|
|
round_img.paste(resized, (0, 0), mask)
|
|
round_img.save(os.path.join(folder, 'ic_launcher_round.png'), 'PNG')
|
|
|
|
# 3. Adaptive Foreground & Background
|
|
fg = make_adaptive_foreground(sz_adapt)
|
|
fg.save(os.path.join(folder, 'ic_launcher_foreground.png'), 'PNG')
|
|
|
|
bg = make_adaptive_background(sz_adapt)
|
|
bg.save(os.path.join(folder, 'ic_launcher_background.png'), 'PNG')
|
|
|
|
print(f"Updated {folder}: Legacy {sz_legacy}x{sz_legacy}, Adaptive {sz_adapt}x{sz_adapt}")
|
|
|
|
# 3. Adaptive XMLs for Android 8.0+ (API 26+)
|
|
anydpi_folder = 'android/app/src/main/res/mipmap-anydpi-v26'
|
|
os.makedirs(anydpi_folder, exist_ok=True)
|
|
|
|
ic_launcher_xml = """<?xml version="1.0" encoding="utf-8"?>
|
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
|
<background android:drawable="@mipmap/ic_launcher_background"/>
|
|
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
|
</adaptive-icon>
|
|
"""
|
|
|
|
with open(os.path.join(anydpi_folder, 'ic_launcher.xml'), 'w') as f:
|
|
f.write(ic_launcher_xml)
|
|
|
|
with open(os.path.join(anydpi_folder, 'ic_launcher_round.xml'), 'w') as f:
|
|
f.write(ic_launcher_xml)
|
|
|
|
print("Created mipmap-anydpi-v26 XMLs for native Android Adaptive Icons!")
|
|
|
|
# 4. Web icons
|
|
src.resize((16, 16), Image.Resampling.LANCZOS).save('web/favicon.png', 'PNG')
|
|
src.resize((192, 192), Image.Resampling.LANCZOS).save('web/icons/Icon-192.png', 'PNG')
|
|
src.resize((512, 512), Image.Resampling.LANCZOS).save('web/icons/Icon-512.png', 'PNG')
|
|
src.resize((192, 192), Image.Resampling.LANCZOS).save('web/icons/Icon-maskable-192.png', 'PNG')
|
|
src.resize((512, 512), Image.Resampling.LANCZOS).save('web/icons/Icon-maskable-512.png', 'PNG')
|
|
|
|
# 5. iOS icons
|
|
ios_folder = 'ios/Runner/Assets.xcassets/AppIcon.appiconset'
|
|
if os.path.exists(ios_folder):
|
|
for f in os.listdir(ios_folder):
|
|
if f.endswith('.png'):
|
|
path = os.path.join(ios_folder, f)
|
|
with Image.open(path) as existing:
|
|
cur_sz = existing.size
|
|
src.resize(cur_sz, Image.Resampling.LANCZOS).save(path, 'PNG')
|
|
|
|
# 6. macOS icons
|
|
macos_folder = 'macos/Runner/Assets.xcassets/AppIcon.appiconset'
|
|
if os.path.exists(macos_folder):
|
|
for f in os.listdir(macos_folder):
|
|
if f.endswith('.png'):
|
|
path = os.path.join(macos_folder, f)
|
|
with Image.open(path) as existing:
|
|
cur_sz = existing.size
|
|
src.resize(cur_sz, Image.Resampling.LANCZOS).save(path, 'PNG')
|
|
|
|
# 7. Windows ICO
|
|
src.resize((256, 256), Image.Resampling.LANCZOS).save(
|
|
'windows/runner/resources/app_icon.ico',
|
|
format='ICO',
|
|
sizes=[(16, 16), (32, 32), (48, 48), (64, 64), (128, 128), (256, 256)]
|
|
)
|
|
|
|
print("ALL ICONS (ANDROID ADAPTIVE + LEGACY + ALL PLATFORMS) FULLY GENERATED!")
|