#!/usr/bin/env python3 """Recorta la 'chrome' del navegador (pestañas + barra de URL) de un screenshot de ventana de Chrome, dejando solo el contenido de la página. Detecta el borde oscuro→claro: el toolbar es oscuro y el área de contenido del dashboard es clara. Uso: python3 crop_chrome.py [--report] """ import sys from PIL import Image def content_top(img): """Primera fila (desde arriba) donde la mayoría del ancho ya es claro y se mantiene claro: el inicio del contenido de la página.""" w, h = img.size px = img.load() xs = [int(w * f) for f in (0.45, 0.55, 0.65, 0.75, 0.85, 0.92)] run_needed = int(h * 0.04) # debe mantenerse claro este # de filas run = 0 for y in range(h): light = 0 for x in xs: r, g, b = px[x, y][:3] if r > 205 and g > 205 and b > 205: light += 1 if light >= len(xs) - 1: run += 1 if run >= run_needed: return y - run + 1 else: run = 0 return 0 def main(): src, out = sys.argv[1], sys.argv[2] img = Image.open(src).convert("RGB") w, h = img.size top = content_top(img) if "--report" in sys.argv: print(f"size={w}x{h} content_top_px={top} (~{top/2:.0f}pt @2x)") cropped = img.crop((0, top, w, h)) cropped.save(out) print(f"OK {out} ({cropped.width}x{cropped.height}, recortado {top}px arriba)") if __name__ == "__main__": main()