INNER CODE UNIT · Python
leer_dimensiones_png
Hainrixz/whatsapp-agentkit · scripts/audit.py:647
def leer_dimensiones_png(ruta: Path) -> tuple[int, int]:
"""
Lee ancho y alto directo de la cabecera IHDR del PNG, sin Pillow.
Layout: 8 bytes de firma, 4 de longitud del chunk, 4 del tipo ("IHDR"),
y despues ancho y alto como uint32 big-endian -> bytes 16..24.
"""
with ruta.open("rb") as f:
cabecera = f.read(24)
if len(cabecera) < 24 or not cabecera.startswith(FIRMA_PNG):
raise ValueError("no tiene una firma PNG valida")
if cabecera[12:16] != b"IHDR":
raise ValueError("el primer chunk no es IHDR")
ancho, alto = struct.unpack(">II", cabecera[16:24])
return ancho, alto
def chequeo_6_imagenes(raiz: Path) -> Resultado: