mirror of
https://github.com/FromGram/server.git
synced 2026-11-16 04:24:52 +03:00
afad55519c
Point public defaults at t.fromchat.ru, harden service-notification delivery, add Stars paid-invite subscriptions plus StarsTestBot, demote blank text_color emoji thumbs, and expose live OTP codes in the admin panel.
76 lines
2.6 KiB
Python
76 lines
2.6 KiB
Python
#!/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'<path[^>]+fill="#FFFFFF"[^>]*d="([^"]+)"', svg, flags=re.I)
|
|
if not paths:
|
|
paths = re.findall(r'<path[^>]+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'''<?xml version="1.0" encoding="utf-8"?>
|
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
android:width="108dp"
|
|
android:height="108dp"
|
|
android:viewportWidth="{viewport_w}"
|
|
android:viewportHeight="{viewport_h}">
|
|
<path
|
|
android:pathData="{plane}"
|
|
android:fillColor="#FFFFFF"
|
|
android:fillType="evenOdd" />
|
|
</vector>
|
|
'''
|
|
(drawable_dir / "fromgram_icon_plane.xml").write_text(plane_xml, encoding="utf-8")
|
|
print("wrote fromgram_icon_plane.xml")
|
|
|
|
inset_xml = '''<?xml version="1.0" encoding="utf-8"?>
|
|
<inset xmlns:android="http://schemas.android.com/apk/res/android"
|
|
android:drawable="@drawable/fromgram_icon_plane"
|
|
android:inset="18%" />
|
|
'''
|
|
(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)
|