feat: initial commit of AI Comic Generator

This commit is contained in:
p
2026-01-17 15:26:14 +08:00
commit 06d76e0e69
278 changed files with 8612 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
import os
from PIL import Image
import io
def split_comic_page(image_bytes: bytes) -> list[bytes]:
"""Splits a 2x2 grid comic page into 4 individual panel images (bytes)."""
try:
img = Image.open(io.BytesIO(image_bytes))
width, height = img.size
mid_w = width // 2
mid_h = height // 2
quadrants = [
(0, 0, mid_w, mid_h), # Top-Left
(mid_w, 0, width, mid_h), # Top-Right
(0, mid_h, mid_w, height), # Bottom-Left
(mid_w, mid_h, width, height) # Bottom-Right
]
panels = []
for box in quadrants:
panel = img.crop(box)
buf = io.BytesIO()
panel.save(buf, format="PNG")
panels.append(buf.getvalue())
return panels
except Exception as e:
print(f"Failed to split image: {e}")
return []