249 lines
7.8 KiB
Python
249 lines
7.8 KiB
Python
"""Generate TLoto brand PNGs and distribute to web/mobile icon slots."""
|
|
from __future__ import annotations
|
|
|
|
import math
|
|
import shutil
|
|
from pathlib import Path
|
|
|
|
from PIL import Image, ImageDraw, ImageFilter
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
BRAND = ROOT / "brand"
|
|
AI_SRC = Path(
|
|
r"C:\Users\ADMIN\.cursor\projects\d-Projects-Workplace-Own-Projects-games-app\assets\tloto-mark-final.jpg"
|
|
)
|
|
if not AI_SRC.exists():
|
|
AI_SRC = Path(
|
|
r"C:\Users\ADMIN\.cursor\projects\d-Projects-Workplace-Own-Projects-games-app\assets\tloto-mark-v1.jpg"
|
|
)
|
|
|
|
NAVY = (11, 15, 26, 255)
|
|
GOLD = (212, 175, 55, 255)
|
|
EMERALD_TOP = (52, 211, 153, 255)
|
|
EMERALD = (16, 185, 129, 255)
|
|
EMERALD_DEEP = (4, 120, 87, 255)
|
|
|
|
|
|
def _lerp(a, b, t: float):
|
|
return tuple(int(a[i] + (b[i] - a[i]) * t) for i in range(4))
|
|
|
|
|
|
def _rounded_rect_mask(size: int, radius: int) -> Image.Image:
|
|
m = Image.new("L", (size, size), 0)
|
|
d = ImageDraw.Draw(m)
|
|
d.rounded_rectangle((0, 0, size - 1, size - 1), radius=radius, fill=255)
|
|
return m
|
|
|
|
|
|
def draw_mark(size: int = 1024) -> Image.Image:
|
|
"""Vector-like raster of the fused T+L mark."""
|
|
s = size
|
|
img = Image.new("RGBA", (s, s), (0, 0, 0, 0))
|
|
draw = ImageDraw.Draw(img)
|
|
|
|
# Background squircle
|
|
bg = Image.new("RGBA", (s, s), (0, 0, 0, 0))
|
|
bg_draw = ImageDraw.Draw(bg)
|
|
rr = int(s * 0.22)
|
|
bg_draw.rounded_rectangle((0, 0, s - 1, s - 1), radius=rr, fill=NAVY)
|
|
# Gold border
|
|
inset = int(s * 0.05)
|
|
border_w = max(2, int(s * 0.022))
|
|
bg_draw.rounded_rectangle(
|
|
(inset, inset, s - 1 - inset, s - 1 - inset),
|
|
radius=max(1, rr - inset // 2),
|
|
outline=GOLD,
|
|
width=border_w,
|
|
)
|
|
img = Image.alpha_composite(img, bg)
|
|
draw = ImageDraw.Draw(img)
|
|
|
|
# Glyph geometry in 128-space scaled
|
|
def xy(x: float, y: float) -> tuple[float, float]:
|
|
return x / 128 * s, y / 128 * s
|
|
|
|
# Continuous TL path points (outer contour)
|
|
pts = [
|
|
xy(34, 24),
|
|
xy(84, 24),
|
|
xy(102, 40),
|
|
xy(84, 56),
|
|
xy(54, 56),
|
|
xy(54, 74),
|
|
xy(76, 74),
|
|
xy(94, 90),
|
|
xy(76, 106),
|
|
xy(34, 106),
|
|
xy(17, 90),
|
|
xy(17, 40),
|
|
]
|
|
|
|
# Build filled glyph on its own layer for gradient
|
|
glyph = Image.new("RGBA", (s, s), (0, 0, 0, 0))
|
|
gdraw = ImageDraw.Draw(glyph)
|
|
|
|
# Approximate smooth TL with thick rounded polygon + rounded bars
|
|
# Top canopy (T)
|
|
top = [
|
|
xy(28, 28),
|
|
xy(88, 28),
|
|
xy(100, 40),
|
|
xy(88, 52),
|
|
xy(50, 52),
|
|
xy(50, 40),
|
|
xy(28, 40),
|
|
]
|
|
# Stem
|
|
stem = [
|
|
xy(28, 40),
|
|
xy(50, 40),
|
|
xy(50, 88),
|
|
xy(28, 88),
|
|
]
|
|
# Foot (L)
|
|
foot = [
|
|
xy(28, 78),
|
|
xy(82, 78),
|
|
xy(94, 90),
|
|
xy(82, 102),
|
|
xy(28, 102),
|
|
]
|
|
|
|
def fill_soft(poly, color):
|
|
gdraw.polygon(poly, fill=color)
|
|
|
|
# Gradient by layered fills
|
|
fill_soft(top, EMERALD_TOP)
|
|
fill_soft(stem, EMERALD)
|
|
fill_soft(foot, EMERALD_DEEP)
|
|
|
|
# Soften joints with overlapping rounded rects
|
|
x0, y0 = xy(28, 28)
|
|
x1, y1 = xy(50, 102)
|
|
gdraw.rounded_rectangle((x0, y0, x1, y1), radius=int(s * 0.06), fill=EMERALD)
|
|
# Top arm
|
|
tx0, ty0 = xy(28, 28)
|
|
tx1, ty1 = xy(100, 52)
|
|
gdraw.rounded_rectangle((tx0, ty0, tx1, ty1), radius=int(s * 0.07), fill=EMERALD_TOP)
|
|
# Blend mid
|
|
mx0, my0 = xy(28, 40)
|
|
mx1, my1 = xy(92, 52)
|
|
gdraw.rounded_rectangle((mx0, my0, mx1, my1), radius=int(s * 0.05), fill=EMERALD)
|
|
# L foot
|
|
fx0, fy0 = xy(28, 78)
|
|
fx1, fy1 = xy(94, 102)
|
|
gdraw.rounded_rectangle((fx0, fy0, fx1, fy1), radius=int(s * 0.07), fill=EMERALD)
|
|
|
|
# Slight blur then re-composite for premium softness at edges
|
|
glyph = glyph.filter(ImageFilter.GaussianBlur(radius=max(0.4, s / 900)))
|
|
# Re-sharpen core by overlaying unblurred core at lower opacity handled via mask
|
|
core = Image.new("RGBA", (s, s), (0, 0, 0, 0))
|
|
cdraw = ImageDraw.Draw(core)
|
|
cdraw.rounded_rectangle((x0, y0, x1, y1), radius=int(s * 0.06), fill=EMERALD)
|
|
cdraw.rounded_rectangle((tx0, ty0, tx1, ty1), radius=int(s * 0.07), fill=EMERALD_TOP)
|
|
cdraw.rounded_rectangle((fx0, fy0, fx1, fy1), radius=int(s * 0.07), fill=EMERALD)
|
|
glyph = Image.alpha_composite(glyph, core)
|
|
|
|
img = Image.alpha_composite(img, glyph)
|
|
draw = ImageDraw.Draw(img)
|
|
|
|
# Gold spark at joint
|
|
cx, cy = xy(54, 52)
|
|
r = s * 0.028
|
|
spark = [
|
|
(cx, cy - r * 1.7),
|
|
(cx + r * 0.35, cy - r * 0.35),
|
|
(cx + r * 1.7, cy),
|
|
(cx + r * 0.35, cy + r * 0.35),
|
|
(cx, cy + r * 1.7),
|
|
(cx - r * 0.35, cy + r * 0.35),
|
|
(cx - r * 1.7, cy),
|
|
(cx - r * 0.35, cy - r * 0.35),
|
|
]
|
|
draw.polygon(spark, fill=GOLD)
|
|
|
|
return img
|
|
|
|
|
|
def prepare_from_ai(size: int = 1024) -> Image.Image | None:
|
|
if not AI_SRC.exists():
|
|
return None
|
|
src = Image.open(AI_SRC).convert("RGBA")
|
|
# Center-crop to square
|
|
w, h = src.size
|
|
side = min(w, h)
|
|
left = (w - side) // 2
|
|
top = (h - side) // 2
|
|
src = src.crop((left, top, left + side, top + side))
|
|
src = src.resize((size, size), Image.Resampling.LANCZOS)
|
|
# Apply squircle mask so PNG edges are clean for adaptive icons
|
|
mask = _rounded_rect_mask(size, int(size * 0.22))
|
|
out = Image.new("RGBA", (size, size), (0, 0, 0, 0))
|
|
out.paste(src, (0, 0))
|
|
out.putalpha(mask)
|
|
return out
|
|
|
|
|
|
def save_png(img: Image.Image, path: Path, size: int | None = None) -> None:
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
out = img if size is None else img.resize((size, size), Image.Resampling.LANCZOS)
|
|
if out.mode != "RGBA":
|
|
out = out.convert("RGBA")
|
|
out.save(path, format="PNG", optimize=True)
|
|
|
|
|
|
def make_lockup(mark: Image.Image, width: int = 1600, height: int = 512) -> Image.Image:
|
|
canvas = Image.new("RGBA", (width, height), (0, 0, 0, 0))
|
|
mark_size = height
|
|
m = mark.resize((mark_size, mark_size), Image.Resampling.LANCZOS)
|
|
canvas.paste(m, (0, 0), m)
|
|
# Wordmark drawn by SVG/text elsewhere; keep mark-only lockup base transparent
|
|
# Consumers use SVG lockup for text; PNG lockup = mark + transparent padding
|
|
return canvas
|
|
|
|
|
|
def distribute(master: Image.Image) -> None:
|
|
# Brand master
|
|
save_png(master, BRAND / "prediqo-mark.png", 1024)
|
|
save_png(master, BRAND / "prediqo-app-icon.png", 1024)
|
|
save_png(master, BRAND / "prediqo-mark-source.png", 1024)
|
|
|
|
lockup = make_lockup(master)
|
|
save_png(lockup, BRAND / "prediqo-lockup.png")
|
|
save_png(lockup, BRAND / "prediqo-lockup-source.png")
|
|
|
|
# Web public
|
|
web_brand = ROOT / "prediqo_web" / "public" / "brand"
|
|
save_png(master, web_brand / "prediqo-mark.png", 512)
|
|
save_png(master, web_brand / "prediqo-app-icon.png", 512)
|
|
save_png(lockup, web_brand / "prediqo-lockup.png")
|
|
shutil.copy2(BRAND / "prediqo-mark.svg", web_brand / "prediqo-mark.svg")
|
|
shutil.copy2(BRAND / "prediqo-lockup.svg", web_brand / "prediqo-lockup.svg")
|
|
|
|
# Favicon SVG (same mark)
|
|
shutil.copy2(BRAND / "prediqo-mark.svg", ROOT / "prediqo_web" / "public" / "favicon.svg")
|
|
|
|
# Mobile assets
|
|
mobile_brand = ROOT / "prediqo_mobile" / "assets" / "brand"
|
|
save_png(master, mobile_brand / "prediqo-mark.png", 512)
|
|
save_png(master, mobile_brand / "prediqo-app-icon.png", 1024)
|
|
save_png(lockup, mobile_brand / "prediqo-lockup.png")
|
|
shutil.copy2(BRAND / "prediqo-mark.svg", mobile_brand / "prediqo-mark.svg")
|
|
|
|
# Mobile web favicon
|
|
save_png(master, ROOT / "prediqo_mobile" / "web" / "favicon.png", 192)
|
|
|
|
print("Distributed brand assets.")
|
|
|
|
|
|
def main() -> None:
|
|
ai = prepare_from_ai(1024)
|
|
# Prefer AI master; fall back to vector draw only if AI source is missing.
|
|
master = ai if ai is not None else draw_mark(1024)
|
|
print(f"Using AI master from {AI_SRC}" if ai is not None else "Using vector-drawn master")
|
|
distribute(master)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|