Render curated date-folder photos with title date and place captions

This commit is contained in:
Pigway
2026-10-05 01:36:05 +08:00
parent f5ab1ade77
commit 011339d511
15 changed files with 386 additions and 18 deletions
+8 -4
View File
@@ -14,7 +14,7 @@ from pigway_frame_flow.storage.database import now_iso
Image.MAX_IMAGE_PIXELS = 25_000_000
def convert(data, fit="contain", profile="color"):
def convert(data, fit="contain", profile="color", *, size=(1200, 1600)):
try:
with Image.open(BytesIO(data)) as source:
if source.format not in {"JPEG", "PNG", "WEBP"}:
@@ -27,7 +27,7 @@ def convert(data, fit="contain", profile="color"):
img = canvas.convert("RGB")
if fit == "contain":
result = ImageOps.pad(
img, (1200, 1600), method=Image.Resampling.LANCZOS, color="white"
img, size, method=Image.Resampling.LANCZOS, color="white"
)
else:
center = (0.5, 0.5)
@@ -38,7 +38,11 @@ def convert(data, fit="contain", profile="color"):
thumb.thumbnail((240, 240))
edges = thumb.convert("L").filter(ImageFilter.FIND_EDGES)
w, h = edges.size
cw, ch = (int(h * 0.75), h) if w / h > 0.75 else (w, int(w / 0.75))
cw, ch = (
(int(h * size[0] / size[1]), h)
if w / h > size[0] / size[1]
else (w, int(w * size[1] / size[0]))
)
choices = []
for step in range(11):
x, y = int((w - cw) * step / 10), int((h - ch) * step / 10)
@@ -53,7 +57,7 @@ def convert(data, fit="contain", profile="color"):
(y / (h - ch)) if h != ch else 0.5,
)
result = ImageOps.fit(
img, (1200, 1600), method=Image.Resampling.LANCZOS, centering=center
img, size, method=Image.Resampling.LANCZOS, centering=center
)
if profile == "grayscale":
result = ImageOps.grayscale(result).convert("RGB")