""" LSU lifestyle image: base photo + 5-product cluster (lower-left) + "LSU Golf Gear" text panel (upper-left). Rebuilds everything from the Imgy renders per LSU-composition-handoff.md. Edit the CONFIG section to tweak copy / layout, then re-run: python3 build_lsu_text.py """ from PIL import Image, ImageDraw, ImageFont, ImageFilter import os, json # ---------------- CONFIG ---------------- SRC = "/opt/files/imgy/batches" PHOTO = f"{SRC}/lsu-midnight-cigar/LSU Maggy DJ-10 Midnight Cigar Holder.png" PROD = f"{SRC}/lsu-cluster" OUT = f"{SRC}/lsu-lifestyle-text" OUT_NAME = "LSU-lifestyle-no-text-cluster-raised" # output file name (no extension) PURPLE = (70, 29, 124) # LSU purple #461D7C GOLD = (253, 208, 35) # LSU gold #FDD023 WHITE = (255, 255, 255) EYEBROW = "OFFICIALLY LICENSED" HEADLINE = ["NCAA", "GOLF GEAR"] TAGLINE = "Now available for 44 schools." PRODUCTS = [] # product list removed (text panel = eyebrow + headline + tagline only) SHOW_TEXT = False # False = pictures only, no text panel CLUSTER_W_PCT = 0.48 # was 0.44 CLUSTER_CENTER_Y_PCT = 0.60 # vertical center of cluster (0.5 = middle); None = bottom-left as before MARGIN_PCT = 0.03 PANEL_ALPHA = 225 # 0-255 opacity of purple panel MIN_GAP = 140 # px gap between text panel and top of product cluster AVENIR_C = "/System/Library/Fonts/Avenir Next Condensed.ttc" AVENIR = "/System/Library/Fonts/Avenir Next.ttc" # ---------------- helpers ---------------- def font_by_style(path, style, size): for i in range(20): try: f = ImageFont.truetype(path, size, index=i) except Exception: break if f.getname()[1].lower() == style.lower(): return f raise RuntimeError(f"style {style} not in {path}") def trim(im): return im.crop(im.getbbox()) def load(name): im = Image.open(f"{PROD}/LSU {name}.png").convert("RGBA") return trim(im) # ---------------- Step A: cluster ---------------- prods = {k: load(k) for k in ["Phone Caddy", "Can Cooler", "Cigar Holder", "DJ-10", "Maggy"]} canvas = Image.new("RGBA", (2800, 1800), (0, 0, 0, 0)) def place(im, h, cx, bottom): w = round(im.width * h / im.height) r = im.resize((w, h), Image.LANCZOS) canvas.alpha_composite(r, (round(cx - w / 2), bottom - h)) place(prods["Phone Caddy"], 1120, 1330, 1200) # back place(prods["Can Cooler"], 900, 840, 1500) place(prods["Cigar Holder"], 756, 440, 1500) place(prods["DJ-10"], 840, 1980, 1485) place(prods["Maggy"], 900, 1330, 1540) # front / hero cluster = trim(canvas) # ---------------- Step B: composite + shadow ---------------- photo = Image.open(PHOTO).convert("RGBA") W, H = photo.size margin = round(W * MARGIN_PCT) cw = round(W * CLUSTER_W_PCT) ch = round(cluster.height * cw / cluster.width) cluster = cluster.resize((cw, ch), Image.LANCZOS) cx = margin cy = H - ch - margin if CLUSTER_CENTER_Y_PCT is None else round(H * CLUSTER_CENTER_Y_PCT - ch / 2) alpha = cluster.split()[3] sil = Image.new("RGBA", cluster.size, (0, 0, 0, 255)); sil.putalpha(alpha) sh_h = max(1, round(ch * 0.14)) sil = sil.resize((cw, sh_h), Image.LANCZOS) shadow_layer = Image.new("RGBA", (W, H), (0, 0, 0, 0)) shadow_layer.alpha_composite(sil, (cx, cy + ch - round(sh_h * 0.6))) shadow_layer = shadow_layer.filter(ImageFilter.GaussianBlur(35)) a = shadow_layer.split()[3].point(lambda v: int(v * 0.28)); shadow_layer.putalpha(a) photo.alpha_composite(shadow_layer) photo.alpha_composite(cluster, (cx, cy)) if not SHOW_TEXT: os.makedirs(OUT, exist_ok=True) final = photo.convert("RGB") final.save(f"{OUT}/{OUT_NAME}.png", optimize=True) final.resize((W // 4, H // 4), Image.LANCZOS).save(f"{OUT}/{OUT_NAME}-preview.jpg", quality=85) print(json.dumps({"size": [W, H], "cluster_box": [cx, cy, cx + cw, cy + ch], "cluster_center_y_pct": round((cy + ch / 2) / H, 3)})) raise SystemExit # ---------------- Step C: text panel (upper-left, above cluster) ---------------- pad = 150 px0 = margin py0 = round(H * 0.035) panel_w = round(W * 0.44) # matches cluster width so they line up inner_x = px0 + pad layer = Image.new("RGBA", (W, H), (0, 0, 0, 0)) d = ImageDraw.Draw(layer) def th(f, s): b = d.textbbox((0, 0), s, font=f); return b[3] - b[1], b[1] def layout(S): z = lambda v: max(1, round(v * S)) f_eyebrow = font_by_style(AVENIR_C, "Demi Bold", z(120)) f_head1 = font_by_style(AVENIR_C, "Heavy", z(560)) f_head2 = font_by_style(AVENIR_C, "Heavy", z(330)) f_tag = font_by_style(AVENIR, "Medium Italic", z(125)) f_pname = font_by_style(AVENIR_C, "Bold", z(140)) f_pdesc = font_by_style(AVENIR, "Regular", z(98)) y = py0 + pad; items = []; bullets = [] h, off = th(f_eyebrow, EYEBROW); items.append((inner_x, y - off, EYEBROW, f_eyebrow, GOLD)); y += h + z(40) h, off = th(f_head1, HEADLINE[0]); items.append((inner_x - z(15), y - off, HEADLINE[0], f_head1, WHITE)); y += h + z(50) h, off = th(f_head2, HEADLINE[1]); items.append((inner_x - z(8), y - off, HEADLINE[1], f_head2, GOLD)); y += h + z(60) rule_y = y; y += z(10) h, off = th(f_tag, TAGLINE); items.append((inner_x, y - off, TAGLINE, f_tag, WHITE)); y += h + z(62) for name, desc in PRODUCTS: hn, on = th(f_pname, name); bullets.append((y, hn)) items.append((inner_x + z(95), y - on, name, f_pname, WHITE)); y += hn + z(22) hd, od = th(f_pdesc, desc) items.append((inner_x + z(95), y - od, desc, f_pdesc, (225, 215, 240))); y += hd + z(62) panel_h = y - py0 - z(62) + pad return items, bullets, rule_y, panel_h, z def widest(items): return max(x + d.textbbox((0, 0), t, font=f)[2] for x, yy, t, f, c in items) S = 3.0 while True: items, bullets, rule_y, panel_h, z = layout(S) fits_h = py0 + panel_h <= cy - MIN_GAP fits_w = widest(items) <= px0 + panel_w - pad if (fits_h and fits_w) or S < 0.5: break S -= 0.01 print("text scale", round(S, 2)) # panel + gold accent bar d.rounded_rectangle([px0, py0, px0 + panel_w, py0 + panel_h], radius=70, fill=PURPLE + (PANEL_ALPHA,)) d.rounded_rectangle([px0, py0, px0 + 34, py0 + panel_h], radius=17, fill=GOLD + (255,)) for by, hn in bullets: r = z(26); cyb = by + hn // 2 d.ellipse([inner_x + z(20), cyb - r, inner_x + z(20) + 2 * r, cyb + r], fill=GOLD + (255,)) # soft drop shadow under the panel psh = Image.new("RGBA", (W, H), (0, 0, 0, 0)) ImageDraw.Draw(psh).rounded_rectangle([px0 + 25, py0 + 35, px0 + panel_w + 25, py0 + panel_h + 35], radius=70, fill=(0, 0, 0, 110)) psh = psh.filter(ImageFilter.GaussianBlur(45)) photo.alpha_composite(psh) photo.alpha_composite(layer) # text with subtle shadow for crispness tl = Image.new("RGBA", (W, H), (0, 0, 0, 0)); td = ImageDraw.Draw(tl) for x, yy, s, f, c in items: td.text((x + 6, yy + 8), s, font=f, fill=(0, 0, 0, 120)) tl = tl.filter(ImageFilter.GaussianBlur(6)) td = ImageDraw.Draw(tl) for x, yy, s, f, c in items: td.text((x, yy), s, font=f, fill=c + (255,)) photo.alpha_composite(tl) # ---------------- save + checks ---------------- os.makedirs(OUT, exist_ok=True) final = photo.convert("RGB") final.save(f"{OUT}/{OUT_NAME}.png", optimize=True) final.resize((W // 4, H // 4), Image.LANCZOS).save(f"{OUT}/{OUT_NAME}-preview.jpg", quality=85) text_right = max(x + d.textbbox((0,0), s, font=f)[2] for x, yy, s, f, c in items) print(json.dumps({ "size": [W, H], "panel_box": [px0, py0, px0 + panel_w, py0 + panel_h], "widest_text_right_edge": text_right, "cluster_box": [cx, cy, cx + cw, cy + ch], "gap_panel_to_cluster_px": cy - (py0 + panel_h), "text_overflows_panel": text_right > px0 + panel_w - 60, }, indent=1))