#!/usr/bin/env python3 """Video kapak (thumbnail) üretici — yüksek kontrastlı, bold tipografili Shorts kapağı. Araştırma: agy (Gemini 3.8 Flash), 2026-11-05 — YouTube Shorts CTR unsurları. Kullanım: python3 make_cover.py <çıktı.jpg> \ --at 0.5 \ --headline "1883" --sub "BİR GECEDE YOK OLDU" \ --accent "#FFD400" \ --badge "KANAL ADI" Kurallar (uygulanan araştırma bulguları): - 1080x1920 dikey, safe zone: üst %15 ve alt %35 boş, sweet spot dikeyde %20-60 arası. - Büyük sayı/tarih (headline) + kısa alt metin (sub), toplam ≤4 kelime. - ALL CAPS, Anton/Bebas Neue (yoksa Impact), siyah stroke + hafif drop shadow. - Vurgu rengi (accent) tek bir elemanda (headline ya da sticker kutu arkaplanı) — 60-30-10. - Alt-üst koyu gradient vignette: arkaplanı sönükleştirip metni öne çıkarır. - Üst sol/sağ köşede marka rozeti (badge), küçük ve sabit. """ import argparse import shutil import subprocess import sys from pathlib import Path from PIL import Image, ImageDraw, ImageFilter, ImageFont FONT_DIR = Path(__file__).resolve().parent.parent / "assets" / "fonts" W, H = 1080, 1920 # Safe zone sınırları (araştırmaya göre) TOP_SAFE = int(H * 0.15) # üstte bu kadar boş kalsın (arama çubuğu/durum çubuğu) BOTTOM_SAFE = int(H * 0.65) # bu çizgiden aşağısı UI ile çakışır, metin konmaz RIGHT_SAFE = int(W * 0.82) # sağda bu çizgiden sonrası etkileşim butonları alanı def hex_to_rgb(h): h = h.lstrip("#") return tuple(int(h[i : i + 2], 16) for i in (0, 2, 4)) def extract_frame(video_path, at_seconds, out_path): """ffmpeg ile videodan tek kare çıkarır (zaten 1080x1920 varsayılır).""" ffmpeg = shutil.which("ffmpeg") or "ffmpeg" cmd = [ ffmpeg, "-y", "-ss", str(at_seconds), "-i", str(video_path), "-frames:v", "1", "-q:v", "2", str(out_path), ] r = subprocess.run(cmd, capture_output=True, text=True) if r.returncode != 0: raise SystemExit(f"ffmpeg kare çıkarma başarısız: {r.stderr[-500:]}") def add_vignette(img, top_frac=0.0, bottom_frac=0.42, strength=170): """Üst ve alttan koyu gradient — metni öne çıkarır, araştırmadaki 60-30-10 kuralının %60'lık koyu arka plan kısmı için.""" w, h = img.size overlay = Image.new("L", (w, h), 0) px = overlay.load() top_h = int(h * top_frac) if top_frac else 0 bot_h = int(h * bottom_frac) for y in range(h): a = 0 if top_h and y < top_h: a = max(a, int(strength * (1 - y / top_h))) if y > h - bot_h: d = (y - (h - bot_h)) / bot_h a = max(a, int(strength * d)) if a: for x in range(0, w, 4): # 4px adımla hızlandır px[x, y] = a overlay = overlay.resize((w, h)) black = Image.new("RGB", (w, h), (0, 0, 0)) return Image.composite(black, img, overlay) def load_font(name_hint, size): candidates = { "anton": FONT_DIR / "Anton-Regular.ttf", "bebas": FONT_DIR / "BebasNeue-Regular.ttf", } path = candidates.get(name_hint) if path and path.exists(): return ImageFont.truetype(str(path), size) return ImageFont.truetype("/System/Library/Fonts/Supplemental/Impact.ttf", size) def draw_stroked_text(draw, xy, text, font, fill, stroke_fill=(0, 0, 0), stroke_w=8, anchor="mm", shadow=True): x, y = xy if shadow: draw.text((x + 6, y + 8), text, font=font, fill=(0, 0, 0, 140), anchor=anchor, stroke_width=stroke_w, stroke_fill=(0, 0, 0, 0)) draw.text((x, y), text, font=font, fill=fill, anchor=anchor, stroke_width=stroke_w, stroke_fill=stroke_fill) def fit_font_size(draw, text, font_name, max_width, start_size, min_size=40): size = start_size while size > min_size: f = load_font(font_name, size) bbox = draw.textbbox((0, 0), text, font=f) if bbox[2] - bbox[0] <= max_width: return f, size size -= 6 return load_font(font_name, min_size), min_size def make_cover(video_path, out_path, at_seconds, headline, sub, accent_hex, badge, font_name="anton"): tmp_frame = Path(out_path).with_suffix(".raw.jpg") extract_frame(video_path, at_seconds, tmp_frame) img = Image.open(tmp_frame).convert("RGB").resize((W, H)) img = add_vignette(img, top_frac=0.0, bottom_frac=0.45, strength=180) # Üst şerit: orijinal karedeki etiket/altyazı kalıntılarını tamamen gizle (solid, gradient değil) draw0 = ImageDraw.Draw(img) draw0.rectangle([0, 0, W, TOP_SAFE + 70], fill=(8, 8, 10)) draw = ImageDraw.Draw(img, "RGBA") accent = hex_to_rgb(accent_hex) max_text_w = RIGHT_SAFE - int(W * 0.08) # Sweet spot: dikeyde %20-55 arası (TOP_SAFE altı, BOTTOM_SAFE üstü) sweet_top = TOP_SAFE + 40 sweet_bottom = BOTTOM_SAFE - 40 # Headline (büyük, vurgu renginde) — üstte hf, hsize = fit_font_size(draw, headline.upper(), font_name, max_text_w, 230, 90) hy = sweet_top + hsize // 2 + 10 draw_stroked_text(draw, (W // 2, hy), headline.upper(), hf, fill=accent, stroke_w=14) # Sub (beyaz, daha küçük) — headline altında if sub: sf, ssize = fit_font_size(draw, sub.upper(), font_name, max_text_w, 100, 48) sy = hy + hsize // 2 + ssize // 2 + 24 sy = min(sy, sweet_bottom) draw_stroked_text(draw, (W // 2, sy), sub.upper(), sf, fill=(255, 255, 255), stroke_w=9) # Marka rozeti — küçük sticker, üst sol, safe zone İÇİNDE (TOP_SAFE'in hemen altı) if badge: bf = load_font(font_name, 42) bbox = draw.textbbox((0, 0), badge.upper(), font=bf) bw, bh = bbox[2] - bbox[0], bbox[3] - bbox[1] pad = 18 bx0, by0 = 40, TOP_SAFE + 80 draw.rectangle([bx0, by0, bx0 + bw + pad * 2, by0 + bh + pad * 2], fill=(0, 0, 0, 210)) draw.text((bx0 + pad, by0 + pad - bbox[1]), badge.upper(), font=bf, fill=(255, 255, 255)) img.save(out_path, quality=92) tmp_frame.unlink(missing_ok=True) print(f"OK {out_path} ({W}x{H})") if __name__ == "__main__": ap = argparse.ArgumentParser() ap.add_argument("video") ap.add_argument("out") ap.add_argument("--at", type=float, default=1.0, help="Kareyi hangi saniyeden çıkar") ap.add_argument("--headline", required=True) ap.add_argument("--sub", default="") ap.add_argument("--accent", default="#FFD400") ap.add_argument("--badge", default="") ap.add_argument("--font", default="anton", choices=["anton", "bebas"]) args = ap.parse_args() make_cover(args.video, args.out, args.at, args.headline, args.sub, args.accent, args.badge, args.font)