Spaces:
Sleeping
Sleeping
| """ | |
| generate_icons.py — Run this once to create the extension icons. | |
| Requires Pillow: pip install Pillow | |
| """ | |
| from PIL import Image, ImageDraw, ImageFont | |
| import os | |
| os.makedirs("icons", exist_ok=True) | |
| def make_icon(size): | |
| img = Image.new("RGBA", (size, size), (0, 0, 0, 0)) | |
| draw = ImageDraw.Draw(img) | |
| # Background rounded rect | |
| pad = size // 8 | |
| draw.rounded_rectangle( | |
| [pad, pad, size - pad, size - pad], | |
| radius=size // 5, | |
| fill="#c94a1f" | |
| ) | |
| # Letter "G" for GLM | |
| font_size = int(size * 0.52) | |
| try: | |
| font = ImageFont.truetype("arial.ttf", font_size) | |
| except: | |
| font = ImageFont.load_default() | |
| text = "G" | |
| bbox = draw.textbbox((0, 0), text, font=font) | |
| tw = bbox[2] - bbox[0] | |
| th = bbox[3] - bbox[1] | |
| tx = (size - tw) // 2 - bbox[0] | |
| ty = (size - th) // 2 - bbox[1] | |
| draw.text((tx, ty), text, fill="white", font=font) | |
| img.save(f"icons/icon{size}.png") | |
| print(f"Created icons/icon{size}.png") | |
| for s in [16, 48, 128]: | |
| make_icon(s) | |
| print("Done. Icons created in icons/") | |