File size: 1,650 Bytes
bb94a34 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | from pathlib import Path
from PIL import Image, ImageEnhance, ImageFilter, ImageOps
from backend.engine import image_to_ascii
ROOT = Path(__file__).resolve().parent.parent
SOURCE = ROOT / "assets" / "fallback-master.png"
IMAGE_DIR = ROOT / "frontend" / "public" / "fallbacks"
ASCII_DIR = ROOT / "backend" / "fallback_ascii"
def main() -> None:
IMAGE_DIR.mkdir(parents=True, exist_ok=True)
ASCII_DIR.mkdir(parents=True, exist_ok=True)
source = Image.open(SOURCE).convert("RGB")
for index in range(20):
angle = ((index % 5) - 2) * 1.2
width, height = source.size
inset_x = int(width * (index % 4) * 0.025)
inset_y = int(height * ((index * 3) % 4) * 0.02)
image = source.crop((inset_x, inset_y, width - inset_x, height - inset_y))
image = image.rotate(angle, resample=Image.Resampling.BICUBIC, expand=False)
image = ImageOps.fit(image, (768, 512), method=Image.Resampling.LANCZOS)
image = ImageEnhance.Contrast(image).enhance(0.9 + (index % 5) * 0.09)
image = ImageEnhance.Color(image).enhance(0.45 + (index % 4) * 0.22)
if index % 3 == 0:
image = image.filter(ImageFilter.GaussianBlur(radius=0.45))
if index % 4 == 0:
image = ImageOps.posterize(image, 5)
image_path = IMAGE_DIR / f"fallback-{index + 1:02d}.webp"
ascii_path = ASCII_DIR / f"fallback-{index + 1:02d}.txt"
image.save(image_path, "WEBP", quality=76, method=6)
ascii_path.write_text(image_to_ascii(image), encoding="utf-8")
print("Generated 20 fallback images and ASCII files")
if __name__ == "__main__":
main()
|