You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.6 KiB

#!/usr/bin/env python3
"""Create a favicon.ico from an existing PNG asset.
Usage: python tools/create_favicon.py
Produces: ./favicon.ico
The script will try to import Pillow. If it's not available, it prints instructions.
"""
import os
import sys
ROOT = os.path.dirname(os.path.dirname(__file__))
SRC = os.path.join(ROOT, 'assets', 'BMP_WEWIN.png')
# fallback to assets/Rat/BMP_WEWIN.png if present
if not os.path.exists(SRC):
alt = os.path.join(ROOT, 'assets', 'Rat', 'BMP_WEWIN.png')
if os.path.exists(alt):
SRC = alt
OUT = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'favicon.ico')
def ensure_pillow():
try:
from PIL import Image
return Image
except Exception:
print('Pillow (PIL) is required to run this script. Install with:')
print(' pip install Pillow')
return None
def create_favicon():
Image = ensure_pillow()
if Image is None:
return 2
if not os.path.exists(SRC):
print(f'Source PNG not found: {SRC}')
return 1
try:
img = Image.open(SRC)
# Create multiple sizes for favicon
sizes = [(16, 16), (32, 32), (48, 48), (64, 64)]
icons = [img.resize(s, Image.Resampling.LANCZOS) if hasattr(Image, 'Resampling') else img.resize(s) for s in sizes]
# Save as ICO
icons[0].save(OUT, format='ICO', sizes=sizes)
print(f'Created favicon: {OUT}')
return 0
except Exception as e:
print('Failed to create favicon:', e)
return 3
if __name__ == '__main__':
sys.exit(create_favicon())