#!/usr/bin/env python3 """Generate PhishGuard extension icons at 16, 48, 128 px using pure Python.""" import struct, zlib, os def create_png(width, height, pixels): """Create a minimal PNG from RGBA pixel data.""" def chunk(chunk_type, data): c = chunk_type + data return struct.pack('>I', len(data)) + c + struct.pack('>I', zlib.crc32(c) & 0xffffffff) raw = b'' for y in range(height): raw += b'\x00' for x in range(width): idx = (y * width + x) * 4 raw += bytes(pixels[idx:idx+4]) return (b'\x89PNG\r\n\x1a\n' + chunk(b'IHDR', struct.pack('>IIBBBBB', width, height, 8, 6, 0, 0, 0)) + chunk(b'IDAT', zlib.compress(raw)) + chunk(b'IEND', b'')) def draw_shield_icon(size): """Draw a shield icon with checkmark.""" pixels = [0] * (size * size * 4) cx, cy = size / 2, size / 2 sr, sg, sb = 0x53, 0x4A, 0xB7 hr, hg, hb = 0x7B, 0x73, 0xD4 for y in range(size): for x in range(size): idx = (y * size + x) * 4 nx = (x - cx) / (size / 2) ny = (y - cy) / (size / 2) in_shield = False if ny < -0.05: if abs(nx) < 0.75: in_shield = True elif ny < 0.5: w = 0.75 * (1 - ny * 0.8) if abs(nx) < w: in_shield = True else: w = 0.75 * max(0, (1.0 - ny) * 1.4) if abs(nx) < w: in_shield = True if ny < -0.8: in_shield = False if in_shield: blend = max(0, min(1, 0.5 - nx * 0.3 - ny * 0.2)) r = int(sr + (hr - sr) * blend) g = int(sg + (hg - sg) * blend) b = int(sb + (hb - sb) * blend) pixels[idx:idx+4] = [r, g, b, 255] else: pixels[idx:idx+4] = [0, 0, 0, 0] if size >= 32: check_points = [] for t in range(100): p = t / 100.0 if p < 0.4: pp = p / 0.4 px = int(cx + (-0.25 + pp * 0.25) * size * 0.6) py = int(cy + (-0.1 + pp * 0.3) * size * 0.6) else: pp = (p - 0.4) / 0.6 px = int(cx + (0.0 + pp * 0.35) * size * 0.6) py = int(cy + (0.2 - pp * 0.45) * size * 0.6) check_points.append((px, py)) thickness = max(1, int(size * 0.06)) for px, py in check_points: for dy in range(-thickness, thickness+1): for dx in range(-thickness, thickness+1): xx, yy = px + dx, py + dy if 0 <= xx < size and 0 <= yy < size: idx = (yy * size + xx) * 4 if pixels[idx+3] > 0: pixels[idx:idx+4] = [255, 255, 255, 240] return pixels icons_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'extension', 'icons') os.makedirs(icons_dir, exist_ok=True) for size in [16, 48, 128]: pixels = draw_shield_icon(size) png_data = create_png(size, size, pixels) path = os.path.join(icons_dir, f'icon{size}.png') with open(path, 'wb') as f: f.write(png_data) print(f"Created {path} ({len(png_data)} bytes)") print("Done! All icons generated.")