Spaces:
Sleeping
Sleeping
File size: 767 Bytes
5a731e7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | from PIL import Image
from pathlib import Path
def optimize_images(input_dir="config/institucional/logos", max_size=(800, 800)):
"""Optimiza imágenes institucionales"""
input_path = Path(input_dir)
for img_file in input_path.glob("*.png"):
img = Image.open(img_file)
# Redimensionar si es necesario
img.thumbnail(max_size, Image.Resampling.LANCZOS)
# Guardar como WebP (mejor compresión)
output_file = img_file.with_suffix('.webp')
img.save(output_file, 'WEBP', quality=85, method=6)
print(f"Optimizado: {img_file.name} -> {output_file.name}")
print(f" Reducción: {img_file.stat().st_size / 1024:.1f}KB -> {output_file.stat().st_size / 1024:.1f}KB") |