| |
| """ |
| Generate PWA icons for BattleWords. |
| Creates 192x192 and 512x512 icons with ocean theme and 'BW' text. |
| """ |
|
|
| from PIL import Image, ImageDraw, ImageFont |
| import os |
|
|
| def create_icon(size, filename): |
| """Create a square icon with ocean gradient background and 'BW' text.""" |
|
|
| |
| img = Image.new('RGB', (size, size)) |
| draw = ImageDraw.Draw(img) |
|
|
| |
| water_sky = (29, 100, 200) |
| water_deep = (11, 42, 74) |
|
|
| for y in range(size): |
| |
| ratio = y / size |
| r = int(water_sky[0] * (1 - ratio) + water_deep[0] * ratio) |
| g = int(water_sky[1] * (1 - ratio) + water_deep[1] * ratio) |
| b = int(water_sky[2] * (1 - ratio) + water_deep[2] * ratio) |
| draw.rectangle([(0, y), (size, y + 1)], fill=(r, g, b)) |
|
|
| |
| circle_margin = size // 10 |
| circle_bbox = [circle_margin, circle_margin, size - circle_margin, size - circle_margin] |
|
|
| |
| overlay = Image.new('RGBA', (size, size), (255, 255, 255, 0)) |
| overlay_draw = ImageDraw.Draw(overlay) |
| overlay_draw.ellipse(circle_bbox, fill=(255, 255, 255, 40)) |
|
|
| |
| img = img.convert('RGBA') |
| img = Image.alpha_composite(img, overlay) |
|
|
| |
| font_size = size // 3 |
| try: |
| |
| font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", font_size) |
| except Exception: |
| try: |
| |
| font = ImageFont.truetype("C:/Windows/Fonts/arialbd.ttf", font_size) |
| except Exception: |
| |
| font = ImageFont.load_default() |
|
|
| draw = ImageDraw.Draw(img) |
| text = "BW" |
|
|
| |
| bbox = draw.textbbox((0, 0), text, font=font) |
| text_width = bbox[2] - bbox[0] |
| text_height = bbox[3] - bbox[1] |
|
|
| |
| x = (size - text_width) // 2 |
| y = (size - text_height) // 2 - (bbox[1] // 2) |
|
|
| |
| shadow_offset = size // 50 |
| draw.text((x + shadow_offset, y + shadow_offset), text, fill=(0, 0, 0, 100), font=font) |
| draw.text((x, y), text, fill='white', font=font) |
|
|
| |
| if img.mode == 'RGBA': |
| background = Image.new('RGB', img.size, (11, 42, 74)) |
| background.paste(img, mask=img.split()[3]) |
| img = background |
|
|
| |
| img.save(filename, 'PNG', optimize=True) |
| print(f"[OK] Created {filename} ({size}x{size})") |
|
|
| def main(): |
| """Generate both icon sizes.""" |
| script_dir = os.path.dirname(os.path.abspath(__file__)) |
| static_dir = os.path.join(script_dir, 'battlewords', 'static') |
|
|
| |
| os.makedirs(static_dir, exist_ok=True) |
|
|
| |
| print("Generating PWA icons for BattleWords...") |
| create_icon(192, os.path.join(static_dir, 'icon-192.png')) |
| create_icon(512, os.path.join(static_dir, 'icon-512.png')) |
| print("\n[SUCCESS] PWA icons generated successfully!") |
| print(f" Location: {static_dir}") |
|
|
| if __name__ == '__main__': |
| main() |
|
|