coderdecoder01 commited on
Commit
d7eebff
·
verified ·
1 Parent(s): 8cbf99e

Legibility pass: heavier font weights, larger body text, brighter gold, crf 18

Browse files
Files changed (1) hide show
  1. render_invitation.py +90 -59
render_invitation.py CHANGED
@@ -2,6 +2,7 @@
2
  """
3
  Indian-style animated retirement invitation for Mamta: 1080x1920, 30fps, H.264 MP4.
4
  Maroon/gold palette, rotating mandala, marigold toran, flickering diyas, colour emoji.
 
5
  """
6
  import os, math, subprocess, urllib.request, random
7
  import numpy as np
@@ -16,7 +17,7 @@ os.makedirs(FDIR, exist_ok=True)
16
  BG_TOP, BG_BOT = (78, 15, 36), (44, 7, 20)
17
  GOLD, GOLD_D, GOLD_L = (232, 193, 115), (201, 150, 47), (245, 222, 166)
18
  CREAM, MARIGOLD, ORANGE = (253, 243, 224), (240, 160, 42), (226, 112, 28)
19
- SOFT = (244, 229, 203)
20
 
21
  # ----------------------------------------------------------------- event text
22
  EV = dict(
@@ -28,10 +29,15 @@ EV = dict(
28
  kicker2="IN HONOUR OF",
29
  body2="on the joyous occasion of her retirement",
30
  small2="30 SEPTEMBER 2026",
 
 
31
  message=[
32
- dict(size=47, color=CREAM, lines=["\u201cThe bell is ringing one last time\u2026\u201d"]),
33
- dict(size=42, color=SOFT, lines=["It is now time to say goodbye", "to my teaching profession."]),
34
- dict(size=42, color=SOFT, lines=["To seek your good wishes & blessings,", "a party has been organised."]),
 
 
 
35
  ],
36
  msg_sig="\u2014 Mamta",
37
  msg_foot="A LIFETIME OF TEACHING",
@@ -84,18 +90,44 @@ HAS_RAQM = bool(features.check("raqm"))
84
  HAS_HINDI = HAS_RAQM and "hindi" in FPATH
85
  print("RAQM:", HAS_RAQM, "| Devanagari usable:", HAS_HINDI, flush=True)
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  _fc = {}
88
- def F(kind, size):
89
- key = (kind, size)
90
  if key in _fc:
91
  return _fc[key]
92
  path = FPATH.get(kind) or FPATH.get("serif") or FPATH.get("body")
93
  f = ImageFont.truetype(path, size)
 
94
  _fc[key] = f
95
  return f
96
 
97
  # ----------------------------------------------------------------- colour emoji
98
- EMOJI_PATH, EMOJI_SIZE = None, 137
99
  for i, u in enumerate(EMOJI_URLS):
100
  dest = os.path.join(FDIR, "emoji_%d.ttf" % i)
101
  try:
@@ -103,7 +135,7 @@ for i, u in enumerate(EMOJI_URLS):
103
  except Exception as e:
104
  print("EMOJI download failed: %s" % repr(e)[:80], flush=True)
105
  continue
106
- for size in (137, 109, 128, 96, 160, 72, 48):
107
  ok = False
108
  try:
109
  f = ImageFont.truetype(dest, size)
@@ -111,15 +143,10 @@ for i, u in enumerate(EMOJI_URLS):
111
  ImageDraw.Draw(probe).text((size, size), "\U0001F339", font=f,
112
  embedded_color=True, anchor="mm")
113
  bb = probe.getbbox()
114
- cov = 0.0
115
- if bb:
116
- cov = float((np.array(probe.crop(bb))[..., 3] > 30).mean())
117
  if bb and cov > 0.25:
118
- EMOJI_PATH, EMOJI_SIZE = dest, size
119
- ok = True
120
  print("EMOJI OK %s size=%d coverage=%.2f" % (u.split("/")[-1], size, cov), flush=True)
121
- else:
122
- print("EMOJI blank at size %d (cov=%.2f)" % (size, cov), flush=True)
123
  except Exception as e:
124
  print("EMOJI size %d failed: %s" % (size, repr(e)[:70]), flush=True)
125
  if ok:
@@ -158,10 +185,10 @@ def emoji_layer(chars, height, spacing=16):
158
  return lay
159
 
160
  # ----------------------------------------------------------------- text helper
161
- def text_layer(lines, kind, size, color, tracking=0, line_h=None):
162
- f = F(kind, size)
163
  tmp = Image.new("RGBA", (8, 8)); td = ImageDraw.Draw(tmp)
164
- lh = line_h or int(size * 1.30)
165
  widths = []
166
  for ln in lines:
167
  if tracking:
@@ -184,10 +211,10 @@ def text_layer(lines, kind, size, color, tracking=0, line_h=None):
184
  bb = lay.getbbox()
185
  return lay.crop(bb) if bb else lay
186
 
187
- def fit_layer(lines, kind, size, color, max_w, tracking=0, line_h=None):
188
  s, lay = size, None
189
  while s > 18:
190
- lay = text_layer(lines, kind, s, color, tracking=tracking, line_h=line_h)
191
  if lay.size[0] <= max_w:
192
  return lay
193
  s = int(s * 0.94)
@@ -235,7 +262,7 @@ def build_bg():
235
  d = np.sqrt(((xx - W * 0.5) / (W * 0.80)) ** 2 + ((yy - H * 0.40) / (H * 0.52)) ** 2)
236
  bg += (np.clip(1 - d, 0, 1) ** 2.3)[..., None] * np.array([118, 58, 18], dtype=np.float32)[None, None, :]
237
  v = np.sqrt(((xx - W * 0.5) / (W * 0.56)) ** 2 + ((yy - H * 0.5) / (H * 0.60)) ** 2)
238
- bg *= (1.0 - 0.42 * np.clip(v, 0, 1) ** 2.4)[..., None]
239
  return Image.fromarray(np.clip(bg, 0, 255).astype(np.uint8), "RGB")
240
 
241
  def build_frame():
@@ -355,7 +382,7 @@ def build_monogram(D=600):
355
  im.alpha_composite(lay, (int(c - lay.size[0] / 2), int(c - lay.size[1] / 2)))
356
  return im
357
 
358
- def card_base(width, height, radius=16, fill=(60, 11, 28, 205)):
359
  card = Image.new("RGBA", (width, height), (0, 0, 0, 0))
360
  S = 2
361
  tmp = Image.new("RGBA", (width * S, height * S), (0, 0, 0, 0))
@@ -364,8 +391,8 @@ def card_base(width, height, radius=16, fill=(60, 11, 28, 205)):
364
  card.alpha_composite(tmp.resize((width, height), Image.LANCZOS), (0, 0))
365
  return card
366
 
367
- def make_card(width, title, sections, title_size=66, label_size=26, value_size=46):
368
- Hc = 1600
369
  card = card_base(width, Hc)
370
  y = 74
371
  if title:
@@ -379,34 +406,34 @@ def make_card(width, title, sections, title_size=66, label_size=26, value_size=4
379
  if si:
380
  rw = int(width * 0.34)
381
  card.alpha_composite(rule_strip(rw, 0.55, 1), (int(width / 2 - rw / 2), int(y)))
382
- y += 38
383
- ll = text_layer([sec["label"]], "serif", label_size, GOLD, tracking=11)
384
  card.alpha_composite(ll, (int(width / 2 - ll.size[0] / 2), int(y)))
385
- y += ll.size[1] + 22
386
  for v in sec["values"]:
387
- vl = fit_layer([v], "body", value_size, CREAM, width - 96)
388
  card.alpha_composite(vl, (int(width / 2 - vl.size[0] / 2), int(y)))
389
  y += vl.size[1] + 12
390
- y += 18
391
  used = y + 40
392
  card.alpha_composite(build_lotus(64), (int(width / 2 - 32), int(used - 20)))
393
  return card.crop((0, 0, width, min(Hc, used + 54)))
394
 
395
- def make_message_card(width=880, sig=None, sig_size=58):
396
- Hc = 1600
397
  card = card_base(width, Hc)
398
- y = 86
399
  paras = EV["message"]
400
  for pi, p in enumerate(paras):
401
- lay = fit_layer(p["lines"], "bodyi", p["size"], p["color"], width - 110,
402
- line_h=int(p["size"] * 1.34))
403
  card.alpha_composite(lay, (int(width / 2 - lay.size[0] / 2), int(y)))
404
- y += lay.size[1] + (46 if pi < len(paras) - 1 else 30)
405
  if sig:
406
- sl = fit_layer([sig], "script", sig_size, GOLD, width - 160)
407
  card.alpha_composite(sl, (int(width / 2 - sl.size[0] / 2), int(y)))
408
  y += sl.size[1]
409
- return card.crop((0, 0, width, min(Hc, y + 74)))
410
 
411
  # ----------------------------------------------------------------- build assets
412
  print("building assets ...", flush=True)
@@ -427,17 +454,17 @@ MOTES = [dict(x=random.uniform(70, W - 70), y=random.uniform(0, H), sp=random.un
427
  for _ in range(16)]
428
 
429
  MAXW = 880
430
- kicker1 = text_layer([EV["hindi"]], "hindi", 46, GOLD) if HAS_HINDI else \
431
- text_layer([EV["kicker1_en"]], "serif", 34, GOLD, tracking=13)
432
- k1_extra = text_layer([EV["kicker1_en"]], "serif", 26, GOLD, tracking=11) if HAS_HINDI else None
433
 
434
  L_script1 = fit_layer([EV["script1"]], "script", 158, GOLD, MAXW)
435
- L_sub1 = fit_layer([EV["sub1"]], "bodyi", 46, SOFT, MAXW)
436
- L_kick2 = text_layer([EV["kicker2"]], "serif", 32, GOLD, tracking=15)
437
  L_name = fit_layer([EV["name"]], "script", 250, CREAM, MAXW)
438
  L_name_glow = alpha_scale(fit_layer([EV["name"]], "script", 250, GOLD, MAXW).filter(ImageFilter.GaussianBlur(16)), 0.55)
439
- L_body2 = fit_layer([EV["body2"]], "bodyi", 47, SOFT, MAXW)
440
- L_small2 = text_layer([EV["small2"]], "serif", 28, GOLD, tracking=10)
441
 
442
  EMOJI_ROSE = emoji_layer(["\U0001F339"], 62)
443
  EMOJI_ROW = emoji_layer(["\U0001F339", "\U0001F64F", "\U0001F389", "\U0001F38A"], 62)
@@ -446,23 +473,23 @@ if EMOJI_ROW is None:
446
  EMOJI_ROW = build_lotus(62)
447
 
448
  CARD_MSG = make_message_card(sig=EV["msg_sig"])
449
- L_foot3 = text_layer([EV["msg_foot"]], "serif", 26, GOLD, tracking=12)
450
- CARD_D = make_card(832, EV["card_title"], [
451
  dict(label=EV["when_label"], values=[EV["when_1"]]),
452
  dict(label=EV["time_label"], values=[EV["time_1"]]),
453
  dict(label=EV["where_label"], values=[EV["where_1"]]),
454
  ])
455
- L_sub3 = fit_layer([EV["sub3"]], "bodyi", 42, SOFT, MAXW)
456
- L_kick3 = text_layer(["THE CELEBRATION"], "serif", 32, GOLD, tracking=15)
457
  MONO = build_monogram(600)
458
- L_quote = fit_layer(EV["quote"], "bodyi", 47, SOFT, MAXW - 60, line_h=76)
459
- L_kick6 = text_layer([EV["kicker6"]], "serif", 30, GOLD, tracking=13)
460
  L_script6 = fit_layer([EV["script6"]], "script", 136, GOLD, MAXW)
461
- L_sig = fit_layer([EV["sig"]], "script", 80, CREAM, MAXW)
462
  print("card sizes: message=%s details=%s emoji=%s" % (CARD_MSG.size, CARD_D.size, EMOJI_PATH is not None), flush=True)
463
 
464
  # ----------------------------------------------------------------- timeline
465
- DUR = [4.5, 5.0, 8.0, 7.0, 5.0, 5.5]
466
  OV, HOLD, FADES = 0.55, 2.0, 0.75
467
  start, acc = [], 0.0
468
  for d in DUR:
@@ -495,9 +522,9 @@ ITEMS = [
495
  (L_sub1, 0.556, 1.05, 40, 0.9)],
496
  [(L_kick2, 0.297, 0.10, 38, 0.9), (L_name_glow, 0.415, 0.42, 58, 1.1), (L_name, 0.415, 0.42, 58, 1.1),
497
  (LOTUS, 0.525, 0.88, 18, 0.8), (L_body2, 0.588, 1.00, 40, 0.9), (L_small2, 0.650, 1.20, 30, 0.9)],
498
- [(EMOJI_ROSE, 0.175, 0.15, 30, 0.8), (CARD_MSG, 0.470, 0.45, 54, 1.05),
499
- (L_foot3, 0.705, 1.10, 34, 0.9)],
500
- [(L_kick3, 0.252, 0.10, 38, 0.9), (CARD_D, 0.500, 0.40, 56, 1.05), (L_sub3, 0.748, 1.05, 40, 0.9)],
501
  [(MONO, 0.395, 0.20, 50, 1.05), (LOTUS_S, 0.545, 0.90, 18, 0.8), (L_quote, 0.645, 1.05, 44, 1.0)],
502
  [(L_kick6, 0.330, 0.15, 36, 0.9), (EMOJI_ROW, 0.392, 0.45, 34, 0.85),
503
  (L_script6, 0.468, 0.65, 58, 1.05), (LOTUS, 0.545, 0.95, 18, 0.8), (L_sig, 0.612, 1.10, 44, 0.95)],
@@ -549,7 +576,7 @@ FFMPEG = get_ffmpeg_exe()
549
  print("ffmpeg:", FFMPEG, flush=True)
550
  proc = subprocess.Popen([FFMPEG, "-y", "-loglevel", "error", "-f", "rawvideo", "-pix_fmt", "rgb24",
551
  "-s", "%dx%d" % (W, H), "-r", str(FPS), "-i", "-",
552
- "-c:v", "libx264", "-preset", "medium", "-crf", "20", "-pix_fmt", "yuv420p",
553
  "-movflags", "+faststart", "-an", OUT], stdin=subprocess.PIPE)
554
 
555
  poster_t = start[1] + 2.6
@@ -567,20 +594,24 @@ print("encoded:", OUT, os.path.getsize(OUT), "bytes", flush=True)
567
 
568
  PREVIEW_DIR = "/tmp/previews"
569
  os.makedirs(PREVIEW_DIR, exist_ok=True)
570
- checks = [("s1", start[0] + 3.4), ("s2", start[1] + 3.2), ("s3", start[2] + 5.5),
571
  ("s4", start[3] + 5.2), ("s5", start[4] + 3.0), ("s6", start[5] + 3.9)]
572
  previews = []
573
  for name, tt in checks:
574
  fp = os.path.join(PREVIEW_DIR, "preview_%s.jpg" % name)
575
- render(tt).save(fp, quality=88)
576
  previews.append(fp)
577
  print("preview", name, "t=%.2f" % tt, flush=True)
578
 
579
  # ----------------------------------------------------------------- upload
580
  from huggingface_hub import HfApi
581
  REPO = os.environ.get("REPO_ID", "coderdecoder01/retirement-invitation-mamta")
582
- api = HfApi(token=os.environ.get("HF_TOKEN"))
583
  api.create_repo(repo_id=REPO, repo_type="dataset", private=False, exist_ok=True)
 
 
 
 
584
  api.upload_file(path_or_fileobj=OUT, path_in_repo="mamta-retirement-invitation.mp4", repo_id=REPO, repo_type="dataset")
585
  api.upload_file(path_or_fileobj=POSTER, path_in_repo="poster.jpg", repo_id=REPO, repo_type="dataset")
586
  for fp in previews:
 
2
  """
3
  Indian-style animated retirement invitation for Mamta: 1080x1920, 30fps, H.264 MP4.
4
  Maroon/gold palette, rotating mandala, marigold toran, flickering diyas, colour emoji.
5
+ v4: legibility pass - critical text in Playfair Display Medium, accent text in weighted Cormorant.
6
  """
7
  import os, math, subprocess, urllib.request, random
8
  import numpy as np
 
17
  BG_TOP, BG_BOT = (78, 15, 36), (44, 7, 20)
18
  GOLD, GOLD_D, GOLD_L = (232, 193, 115), (201, 150, 47), (245, 222, 166)
19
  CREAM, MARIGOLD, ORANGE = (253, 243, 224), (240, 160, 42), (226, 112, 28)
20
+ SOFT = (246, 234, 212)
21
 
22
  # ----------------------------------------------------------------- event text
23
  EV = dict(
 
29
  kicker2="IN HONOUR OF",
30
  body2="on the joyous occasion of her retirement",
31
  small2="30 SEPTEMBER 2026",
32
+ # 'serif' = Playfair Display (sturdier, used for anything that must be read clearly)
33
+ # 'bodyi' = Cormorant Italic (decorative flourishes only)
34
  message=[
35
+ dict(kind="bodyi", size=54, color=CREAM, weight=600,
36
+ lines=["\u201cThe bell is ringing one last time\u2026\u201d"]),
37
+ dict(kind="serif", size=48, color=CREAM, weight=500,
38
+ lines=["It is now time to say goodbye", "to my teaching profession."]),
39
+ dict(kind="serif", size=46, color=CREAM, weight=500,
40
+ lines=["To seek your good wishes & blessings,", "a party has been organised."]),
41
  ],
42
  msg_sig="\u2014 Mamta",
43
  msg_foot="A LIFETIME OF TEACHING",
 
90
  HAS_HINDI = HAS_RAQM and "hindi" in FPATH
91
  print("RAQM:", HAS_RAQM, "| Devanagari usable:", HAS_HINDI, flush=True)
92
 
93
+ def _set_weight(f, weight):
94
+ """Set only the wght axis of a variable font, leaving other axes at default."""
95
+ if not weight:
96
+ return
97
+ try:
98
+ axes = f.get_variation_axes()
99
+ except Exception:
100
+ return
101
+ vals = []
102
+ for ax in axes:
103
+ name = ax.get("name", "") if isinstance(ax, dict) else getattr(ax, "name", "")
104
+ dflt = ax.get("default", 0) if isinstance(ax, dict) else getattr(ax, "default", 0)
105
+ vals.append(weight if "eight" in str(name) else dflt)
106
+ try:
107
+ f.set_variation_by_axes(vals)
108
+ print(" weight %s -> %s on %s" % (weight, vals, name_of(f)), flush=True)
109
+ except Exception as e:
110
+ print(" weight FAIL %s" % repr(e)[:80], flush=True)
111
+
112
+ def name_of(f):
113
+ try:
114
+ return f.getname()
115
+ except Exception:
116
+ return "?"
117
+
118
  _fc = {}
119
+ def F(kind, size, weight=None):
120
+ key = (kind, size, weight)
121
  if key in _fc:
122
  return _fc[key]
123
  path = FPATH.get(kind) or FPATH.get("serif") or FPATH.get("body")
124
  f = ImageFont.truetype(path, size)
125
+ _set_weight(f, weight)
126
  _fc[key] = f
127
  return f
128
 
129
  # ----------------------------------------------------------------- colour emoji
130
+ EMOJI_PATH, EMOJI_SIZE = None, 109
131
  for i, u in enumerate(EMOJI_URLS):
132
  dest = os.path.join(FDIR, "emoji_%d.ttf" % i)
133
  try:
 
135
  except Exception as e:
136
  print("EMOJI download failed: %s" % repr(e)[:80], flush=True)
137
  continue
138
+ for size in (109, 137, 128, 96, 160, 72, 48):
139
  ok = False
140
  try:
141
  f = ImageFont.truetype(dest, size)
 
143
  ImageDraw.Draw(probe).text((size, size), "\U0001F339", font=f,
144
  embedded_color=True, anchor="mm")
145
  bb = probe.getbbox()
146
+ cov = float((np.array(probe.crop(bb))[..., 3] > 30).mean()) if bb else 0.0
 
 
147
  if bb and cov > 0.25:
148
+ EMOJI_PATH, EMOJI_SIZE, ok = dest, size, True
 
149
  print("EMOJI OK %s size=%d coverage=%.2f" % (u.split("/")[-1], size, cov), flush=True)
 
 
150
  except Exception as e:
151
  print("EMOJI size %d failed: %s" % (size, repr(e)[:70]), flush=True)
152
  if ok:
 
185
  return lay
186
 
187
  # ----------------------------------------------------------------- text helper
188
+ def text_layer(lines, kind, size, color, tracking=0, line_h=None, weight=None):
189
+ f = F(kind, size, weight)
190
  tmp = Image.new("RGBA", (8, 8)); td = ImageDraw.Draw(tmp)
191
+ lh = line_h or int(size * 1.32)
192
  widths = []
193
  for ln in lines:
194
  if tracking:
 
211
  bb = lay.getbbox()
212
  return lay.crop(bb) if bb else lay
213
 
214
+ def fit_layer(lines, kind, size, color, max_w, tracking=0, line_h=None, weight=None):
215
  s, lay = size, None
216
  while s > 18:
217
+ lay = text_layer(lines, kind, s, color, tracking=tracking, line_h=line_h, weight=weight)
218
  if lay.size[0] <= max_w:
219
  return lay
220
  s = int(s * 0.94)
 
262
  d = np.sqrt(((xx - W * 0.5) / (W * 0.80)) ** 2 + ((yy - H * 0.40) / (H * 0.52)) ** 2)
263
  bg += (np.clip(1 - d, 0, 1) ** 2.3)[..., None] * np.array([118, 58, 18], dtype=np.float32)[None, None, :]
264
  v = np.sqrt(((xx - W * 0.5) / (W * 0.56)) ** 2 + ((yy - H * 0.5) / (H * 0.60)) ** 2)
265
+ bg *= (1.0 - 0.34 * np.clip(v, 0, 1) ** 2.4)[..., None]
266
  return Image.fromarray(np.clip(bg, 0, 255).astype(np.uint8), "RGB")
267
 
268
  def build_frame():
 
382
  im.alpha_composite(lay, (int(c - lay.size[0] / 2), int(c - lay.size[1] / 2)))
383
  return im
384
 
385
+ def card_base(width, height, radius=16, fill=(60, 11, 28, 215)):
386
  card = Image.new("RGBA", (width, height), (0, 0, 0, 0))
387
  S = 2
388
  tmp = Image.new("RGBA", (width * S, height * S), (0, 0, 0, 0))
 
391
  card.alpha_composite(tmp.resize((width, height), Image.LANCZOS), (0, 0))
392
  return card
393
 
394
+ def make_card(width, title, sections, title_size=66, label_size=28, value_size=48):
395
+ Hc = 1700
396
  card = card_base(width, Hc)
397
  y = 74
398
  if title:
 
406
  if si:
407
  rw = int(width * 0.34)
408
  card.alpha_composite(rule_strip(rw, 0.55, 1), (int(width / 2 - rw / 2), int(y)))
409
+ y += 42
410
+ ll = text_layer([sec["label"]], "serif", label_size, GOLD_L, tracking=12, weight=500)
411
  card.alpha_composite(ll, (int(width / 2 - ll.size[0] / 2), int(y)))
412
+ y += ll.size[1] + 24
413
  for v in sec["values"]:
414
+ vl = fit_layer([v], "serif", value_size, CREAM, width - 96, weight=500)
415
  card.alpha_composite(vl, (int(width / 2 - vl.size[0] / 2), int(y)))
416
  y += vl.size[1] + 12
417
+ y += 20
418
  used = y + 40
419
  card.alpha_composite(build_lotus(64), (int(width / 2 - 32), int(used - 20)))
420
  return card.crop((0, 0, width, min(Hc, used + 54)))
421
 
422
+ def make_message_card(width=900, sig=None, sig_size=64):
423
+ Hc = 1700
424
  card = card_base(width, Hc)
425
+ y = 90
426
  paras = EV["message"]
427
  for pi, p in enumerate(paras):
428
+ lay = fit_layer(p["lines"], p["kind"], p["size"], p["color"], width - 100,
429
+ line_h=int(p["size"] * 1.34), weight=p.get("weight"))
430
  card.alpha_composite(lay, (int(width / 2 - lay.size[0] / 2), int(y)))
431
+ y += lay.size[1] + (48 if pi < len(paras) - 1 else 32)
432
  if sig:
433
+ sl = fit_layer([sig], "script", sig_size, GOLD_L, width - 160)
434
  card.alpha_composite(sl, (int(width / 2 - sl.size[0] / 2), int(y)))
435
  y += sl.size[1]
436
+ return card.crop((0, 0, width, min(Hc, y + 76)))
437
 
438
  # ----------------------------------------------------------------- build assets
439
  print("building assets ...", flush=True)
 
454
  for _ in range(16)]
455
 
456
  MAXW = 880
457
+ kicker1 = text_layer([EV["hindi"]], "hindi", 48, GOLD_L, weight=500) if HAS_HINDI else \
458
+ text_layer([EV["kicker1_en"]], "serif", 34, GOLD_L, tracking=13, weight=500)
459
+ k1_extra = text_layer([EV["kicker1_en"]], "serif", 26, GOLD_L, tracking=11, weight=500) if HAS_HINDI else None
460
 
461
  L_script1 = fit_layer([EV["script1"]], "script", 158, GOLD, MAXW)
462
+ L_sub1 = fit_layer([EV["sub1"]], "serif", 42, SOFT, MAXW, weight=500)
463
+ L_kick2 = text_layer([EV["kicker2"]], "serif", 32, GOLD_L, tracking=15, weight=500)
464
  L_name = fit_layer([EV["name"]], "script", 250, CREAM, MAXW)
465
  L_name_glow = alpha_scale(fit_layer([EV["name"]], "script", 250, GOLD, MAXW).filter(ImageFilter.GaussianBlur(16)), 0.55)
466
+ L_body2 = fit_layer([EV["body2"]], "serif", 44, SOFT, MAXW, weight=500)
467
+ L_small2 = text_layer([EV["small2"]], "serif", 30, GOLD_L, tracking=10, weight=500)
468
 
469
  EMOJI_ROSE = emoji_layer(["\U0001F339"], 62)
470
  EMOJI_ROW = emoji_layer(["\U0001F339", "\U0001F64F", "\U0001F389", "\U0001F38A"], 62)
 
473
  EMOJI_ROW = build_lotus(62)
474
 
475
  CARD_MSG = make_message_card(sig=EV["msg_sig"])
476
+ L_foot3 = text_layer([EV["msg_foot"]], "serif", 28, GOLD_L, tracking=12, weight=500)
477
+ CARD_D = make_card(848, EV["card_title"], [
478
  dict(label=EV["when_label"], values=[EV["when_1"]]),
479
  dict(label=EV["time_label"], values=[EV["time_1"]]),
480
  dict(label=EV["where_label"], values=[EV["where_1"]]),
481
  ])
482
+ L_sub3 = fit_layer([EV["sub3"]], "serif", 42, SOFT, MAXW, weight=500)
483
+ L_kick3 = text_layer(["THE CELEBRATION"], "serif", 32, GOLD_L, tracking=15, weight=500)
484
  MONO = build_monogram(600)
485
+ L_quote = fit_layer(EV["quote"], "bodyi", 54, SOFT, MAXW - 60, line_h=82, weight=600)
486
+ L_kick6 = text_layer([EV["kicker6"]], "serif", 30, GOLD_L, tracking=13, weight=500)
487
  L_script6 = fit_layer([EV["script6"]], "script", 136, GOLD, MAXW)
488
+ L_sig = fit_layer([EV["sig"]], "script", 84, CREAM, MAXW)
489
  print("card sizes: message=%s details=%s emoji=%s" % (CARD_MSG.size, CARD_D.size, EMOJI_PATH is not None), flush=True)
490
 
491
  # ----------------------------------------------------------------- timeline
492
+ DUR = [4.5, 5.0, 8.5, 7.0, 4.5, 5.5]
493
  OV, HOLD, FADES = 0.55, 2.0, 0.75
494
  start, acc = [], 0.0
495
  for d in DUR:
 
522
  (L_sub1, 0.556, 1.05, 40, 0.9)],
523
  [(L_kick2, 0.297, 0.10, 38, 0.9), (L_name_glow, 0.415, 0.42, 58, 1.1), (L_name, 0.415, 0.42, 58, 1.1),
524
  (LOTUS, 0.525, 0.88, 18, 0.8), (L_body2, 0.588, 1.00, 40, 0.9), (L_small2, 0.650, 1.20, 30, 0.9)],
525
+ [(EMOJI_ROSE, 0.170, 0.15, 30, 0.8), (CARD_MSG, 0.455, 0.45, 54, 1.05),
526
+ (L_foot3, 0.712, 1.10, 34, 0.9)],
527
+ [(L_kick3, 0.246, 0.10, 38, 0.9), (CARD_D, 0.505, 0.40, 56, 1.05), (L_sub3, 0.760, 1.05, 40, 0.9)],
528
  [(MONO, 0.395, 0.20, 50, 1.05), (LOTUS_S, 0.545, 0.90, 18, 0.8), (L_quote, 0.645, 1.05, 44, 1.0)],
529
  [(L_kick6, 0.330, 0.15, 36, 0.9), (EMOJI_ROW, 0.392, 0.45, 34, 0.85),
530
  (L_script6, 0.468, 0.65, 58, 1.05), (LOTUS, 0.545, 0.95, 18, 0.8), (L_sig, 0.612, 1.10, 44, 0.95)],
 
576
  print("ffmpeg:", FFMPEG, flush=True)
577
  proc = subprocess.Popen([FFMPEG, "-y", "-loglevel", "error", "-f", "rawvideo", "-pix_fmt", "rgb24",
578
  "-s", "%dx%d" % (W, H), "-r", str(FPS), "-i", "-",
579
+ "-c:v", "libx264", "-preset", "slow", "-crf", "18", "-pix_fmt", "yuv420p",
580
  "-movflags", "+faststart", "-an", OUT], stdin=subprocess.PIPE)
581
 
582
  poster_t = start[1] + 2.6
 
594
 
595
  PREVIEW_DIR = "/tmp/previews"
596
  os.makedirs(PREVIEW_DIR, exist_ok=True)
597
+ checks = [("s1", start[0] + 3.4), ("s2", start[1] + 3.2), ("s3", start[2] + 5.8),
598
  ("s4", start[3] + 5.2), ("s5", start[4] + 3.0), ("s6", start[5] + 3.9)]
599
  previews = []
600
  for name, tt in checks:
601
  fp = os.path.join(PREVIEW_DIR, "preview_%s.jpg" % name)
602
+ render(tt).save(fp, quality=92)
603
  previews.append(fp)
604
  print("preview", name, "t=%.2f" % tt, flush=True)
605
 
606
  # ----------------------------------------------------------------- upload
607
  from huggingface_hub import HfApi
608
  REPO = os.environ.get("REPO_ID", "coderdecoder01/retirement-invitation-mamta")
609
+ api = HfApi(token=os.environ["HF_TOKEN"])
610
  api.create_repo(repo_id=REPO, repo_type="dataset", private=False, exist_ok=True)
611
+ try:
612
+ api.update_repo_settings(repo_id=REPO, repo_type="dataset", private=False)
613
+ except Exception as e:
614
+ print("visibility:", repr(e)[:120], flush=True)
615
  api.upload_file(path_or_fileobj=OUT, path_in_repo="mamta-retirement-invitation.mp4", repo_id=REPO, repo_type="dataset")
616
  api.upload_file(path_or_fileobj=POSTER, path_in_repo="poster.jpg", repo_id=REPO, repo_type="dataset")
617
  for fp in previews: