#!/usr/bin/env python3 """Extract raster gradient and plane path from brand SVG for Android assets. The SVG uses viewBox="0 0 69.2 69.2" with the white plane path in that space. The embedded gradient PNG sits under a scale transform from a 1000x1000 clip. The Android vector viewport must match the path coordinate space (69.2), not 1000 — otherwise the plane is a speck in the corner and looks missing. """ import base64 import pathlib import re import sys svg_path = pathlib.Path(sys.argv[1]) out_dir = pathlib.Path(sys.argv[2]) svg = svg_path.read_text(encoding="utf-8") m = re.search(r'href="data:image/png;base64,([^"]+)"', svg) if not m: raise SystemExit("embedded png not found") png = base64.b64decode(m.group(1)) bg_path = out_dir / "fromgram_icon_background.png" bg_path.write_bytes(png) print(f"wrote background png ({len(png)} bytes)") view_box = re.search(r'viewBox="0\s+0\s+([0-9.]+)\s+([0-9.]+)"', svg) if not view_box: raise SystemExit("viewBox not found") viewport_w = view_box.group(1) viewport_h = view_box.group(2) print(f"viewport {viewport_w}x{viewport_h}") paths = re.findall(r']+fill="#FFFFFF"[^>]*d="([^"]+)"', svg, flags=re.I) if not paths: paths = re.findall(r']+d="([^"]+)"[^>]+fill="#FFFFFF"', svg, flags=re.I) if not paths: raise SystemExit("white plane path not found") plane = re.sub(r"\s+", " ", paths[0]).strip() print(f"plane path chars: {len(plane)}") drawable_dir = out_dir.parent / "drawable" drawable_dir.mkdir(parents=True, exist_ok=True) plane_xml = f''' ''' (drawable_dir / "fromgram_icon_plane.xml").write_text(plane_xml, encoding="utf-8") print("wrote fromgram_icon_plane.xml") inset_xml = ''' ''' (drawable_dir / "fromgram_icon_plane_inset.xml").write_text(inset_xml, encoding="utf-8") print("wrote fromgram_icon_plane_inset.xml") try: from PIL import Image im = Image.open(bg_path).convert("RGB") w, h = im.size top = im.getpixel((w // 2, h // 8)) bottom = im.getpixel((w // 2, h * 7 // 8)) print(f"gradient sample top={top} bottom={bottom}") except Exception as exc: print("pillow sample skipped:", exc)