#!/usr/bin/env python3 """Kisi-kesilmis (arka plan kaldirilmis) kapak uretici. Ne zaman make_cover.py yerine BUNU kullan: - Kullanici cercevedeki (make_cover.py) kapagi begenmeyip "arkami silebilirsin" / "alt yaziyi kaldir" / "baslik daha one cik(s)in" derse. Bu geri bildirim kalibi SABIT: kisi arka plandan ayristirilmis + marka renginde duz/gradient fon + TEK buyuk, kisa (2-3 kelime) baslik, ikinci bir alt-yazi satiri YOK. - make_cover.py video KARESİ uzerine yazi basar (kaynagin kendi arka plani kalir); bu script kisiyi TAMAMEN yeni bir fona tasir — iki farkli "stil", ikisi de gecerli, kullanicinin son tercihine gore sec. Kullanim: python3 make_cover_cutout.py \ --at 2.0 \ --lines "ÖDEVİNİ" "O TAKİP" "ETSİN" \ --accent-line 1 --accent "#FFD100" \ --tag "ÜCRETSİZ" --tag-color "#00C878" \ --badge "HAMARATLABS" Gereksinim: `pip install rembg` (ilk calistirmada ~1GB model indirir, bir kere). """ import argparse import shutil import subprocess from pathlib import Path from PIL import Image, ImageDraw, ImageFilter, ImageFont FONT_DIR = Path(__file__).resolve().parent.parent / "assets" / "fonts" W, H = 1080, 1920 def hex_to_rgb(h): h = h.lstrip("#") return tuple(int(h[i:i + 2], 16) for i in (0, 2, 4)) def load_font(name_hint, size): path = FONT_DIR / ("Anton-Regular.ttf" if name_hint == "anton" else "BebasNeue-Regular.ttf") if path.exists(): return ImageFont.truetype(str(path), size) return ImageFont.truetype("/System/Library/Fonts/Supplemental/Impact.ttf", size) def extract_frame_if_video(src, at_seconds, tmp_path): if str(src).lower().endswith((".jpg", ".jpeg", ".png")): return Path(src) ffmpeg = shutil.which("ffmpeg") or "ffmpeg" cmd = [ffmpeg, "-y", "-ss", str(at_seconds), "-i", str(src), "-frames:v", "1", "-q:v", "1", str(tmp_path)] r = subprocess.run(cmd, capture_output=True, text=True) if r.returncode != 0: raise SystemExit(f"ffmpeg kare cikarma basarisiz: {r.stderr[-500:]}") return tmp_path def remove_background(frame_path): from rembg import new_session, remove # lazy import: agir model, yalniz gerektiginde yuklensin im = Image.open(frame_path).convert("RGBA") # birefnet-portrait: sac tellerinde/kenarlarda u2net'ten cok daha temiz # sonuc verir (agy arastirmasi, 2026-11-06). alpha_matting KAPALI birakilir, # BiRefNet kendi yumusak alfa maskesini zaten uretiyor. try: session = new_session("birefnet-portrait") return remove(im, session=session, alpha_matting=False) except Exception: return remove(im) # model inmemisse/hata varsa eski varsayilana dus def make_gradient_bg(top_rgb, bottom_rgb): bg = Image.new("RGB", (W, H), bottom_rgb) draw = ImageDraw.Draw(bg) for y in range(H): t = y / H r = int(top_rgb[0] + (bottom_rgb[0] - top_rgb[0]) * t) g = int(top_rgb[1] + (bottom_rgb[1] - top_rgb[1]) * t) b = int(top_rgb[2] + (bottom_rgb[2] - top_rgb[2]) * t) draw.line([(0, y), (W, y)], fill=(r, g, b)) return bg def compose(person_rgba, bg_rgb): alpha = person_rgba.split()[3] bbox = alpha.getbbox() if not bbox: raise SystemExit("Arka plan kaldirma kisiyi bulamadi (bos alfa) — kaynak kareyi degistir.") pad = 20 bbox = (max(0, bbox[0] - pad), max(0, bbox[1] - pad), min(person_rgba.width, bbox[2] + pad), min(person_rgba.height, bbox[3] + pad)) person = person_rgba.crop(bbox) # agy arastirmasi (2026-11-06): kisi dikey ekranin %50-65'ini kaplamali, # alt sinira (govde/bel) sifirlanmali ("floating torso" hatasindan kacinmak # icin). Genislik degil YUKSEKLIK esas alinir. target_h = int(H * 0.60) scale = target_h / person.height target_w = int(person.width * scale) person = person.resize((target_w, target_h), Image.LANCZOS) canvas = bg_rgb.convert("RGBA") px = (W - person.width) // 2 # alta sifirla (govde tabanda kesilsin, hic bosluk kalmasin) — "yuzen govde" # hatasini onler; ustte baslik blogu icin (y ~150-970) temiz yer kalir. py = H - target_h + 40 canvas.alpha_composite(person, (px, py)) # Rim light / kenar isigi: kesilen kisi duz zemine "yapistirilmis" gibi # durmasin diye, kenarlarina zemin renginin acik tonunda ince bir disa # isima (outer glow) eklenir (agy arastirmasi, "havada yapistirilmis" hatasi). edge = person.split()[3].filter(ImageFilter.FIND_EDGES).filter(ImageFilter.GaussianBlur(6)) glow_layer = Image.new("RGBA", canvas.size, (255, 255, 255, 0)) glow_color = tuple(min(255, c + 60) for c in bg_rgb.getpixel((W // 2, py))) + (120,) glow_solid = Image.new("RGBA", person.size, glow_color) glow_layer.paste(glow_solid, (px, py), edge) canvas = Image.alpha_composite(canvas, glow_layer) canvas.alpha_composite(person, (px, py)) # sadece en altta hafif koyu bant (zemine oturtmak icin); tepede vignette # YOK — tepedeki koyu bant baslik rengiyle degil, arka plan kontrastiyla # okunurluk sagliyor (bkz. top-color/bottom-color kiyafetten farkli secilmeli). vignette = Image.new("L", (W, H), 0) vd = ImageDraw.Draw(vignette) bottom_band_start = int(H * 0.80) for y in range(bottom_band_start, H): t = (y - bottom_band_start) / (H - bottom_band_start) vd.line([(0, y), (W, y)], fill=int(140 * t)) vignette = vignette.filter(ImageFilter.GaussianBlur(10)) dark = Image.new("RGBA", (W, H), (0, 0, 0, 255)) return Image.composite(dark, canvas, vignette.point(lambda p: p)) def draw_headline(canvas, lines, accent_idx, accent_rgb, font_name="anton"): draw = ImageDraw.Draw(canvas) margin = 60 max_w = W - margin * 2 # agy arastirmasi (2026-11-06): 1080x1920 tuvalde font 110-180px araliginda # kalmali (daha buyugu okunakli gorunse de "ideal metin alani" olan # Y 250-750 bandini tasiyor ve kisiyle cakisiyor). def fit(text, start=180, minimum=70): size = start while size > minimum: f = load_font(font_name, size) bbox = draw.textbbox((0, 0), text, font=f) if bbox[2] - bbox[0] <= max_w: return f, bbox[3] - bbox[1] size -= 4 return load_font(font_name, minimum), 0 sized = [fit(line) for line in lines] y = 170 for i, (line, (f, h)) in enumerate(zip(lines, sized)): color = accent_rgb if i == accent_idx else (255, 255, 255) draw.text((W // 2, y), line, font=f, fill=color, stroke_width=12, stroke_fill=(0, 0, 0), anchor="ma") y += h + 26 return canvas, y # y: baslik blogunun bittigi nokta, tag/badge buna gore konumlanir def draw_tag(canvas, text, color_rgb, y, font_name="anton"): # agy arastirmasi: sag kenar %15-20 (X 900-1080) ve alt %25-30 (Y>1400) # etkilesim butonlari icin ayrilir, metin/rozet KONULMAZ. Bu yuzden rozet # SOLA ve baslik blogunun hemen ALTINA (cagiranin verdigi y) konur. draw = ImageDraw.Draw(canvas) f = load_font(font_name, 64) bbox = draw.textbbox((0, 0), text, font=f) tw, th = bbox[2] - bbox[0], bbox[3] - bbox[1] pad_x, pad_y = 28, 16 x0 = 60 # sol kenardan, sag guvenli seridin disinda y0 = min(y, 1380 - (th + pad_y * 2)) # alt guvenli sinirin (1400) ustunde kalsin draw.rounded_rectangle([x0, y0, x0 + tw + pad_x * 2, y0 + th + pad_y * 2], radius=18, fill=color_rgb) draw.text((x0 + pad_x, y0 + pad_y - bbox[1]), text, font=f, fill=(10, 10, 10), anchor="la") def draw_badge(canvas, text, font_name="bebas"): # agy arastirmasi: alt %25-30 (Y 1400-1920) YouTube/IG arayuzune (abone ol, # hesap adi, aciklama) ayrilir — marka rozeti bu sinirin USTUNDE (Y<=1380) # kalmali, eskiden H-70=1850'de duruyordu ve arayuzle cakisiyordu. draw = ImageDraw.Draw(canvas) f = load_font(font_name, 46) draw.text((60, 1350), text, font=f, fill=(255, 255, 255), stroke_width=5, stroke_fill=(0, 0, 0), anchor="lm") def main(): ap = argparse.ArgumentParser() ap.add_argument("src", help="video (.mp4) ya da zaten cikarilmis kare (.jpg/.png)") ap.add_argument("out") ap.add_argument("--at", type=float, default=1.0) ap.add_argument("--lines", nargs="+", required=True, help="baslik satirlari, 2-3 kisa kelime/satir") ap.add_argument("--accent-line", type=int, default=-1, help="vurgu renginde olacak satirin indeksi (0-based)") ap.add_argument("--accent", default="#FFD100") ap.add_argument("--tag", default="") ap.add_argument("--tag-color", default="#00C878") ap.add_argument("--badge", default="") ap.add_argument("--top-color", default="#FF8C00", help="kiyafet/tema renginden BARIZ farkli sec (varsayilan: parlak turuncu)") ap.add_argument("--bottom-color", default="#140A3C", help="koyu mor/lacivert") args = ap.parse_args() tmp_frame = Path(args.out).with_suffix(".raw.jpg") frame_path = extract_frame_if_video(args.src, args.at, tmp_frame) person = remove_background(frame_path) bg = make_gradient_bg(hex_to_rgb(args.top_color), hex_to_rgb(args.bottom_color)) canvas = compose(person, bg) canvas, headline_bottom_y = draw_headline(canvas, args.lines, args.accent_line, hex_to_rgb(args.accent)) if args.tag: draw_tag(canvas, args.tag, hex_to_rgb(args.tag_color), y=headline_bottom_y + 20) if args.badge: draw_badge(canvas, args.badge) canvas.convert("RGB").save(args.out, quality=95) if tmp_frame.exists() and tmp_frame != Path(args.src): tmp_frame.unlink() print(f"OK {args.out} ({canvas.size})") if __name__ == "__main__": main()