feat: thumbnail picker custom per selezione modello/scena

- GET /folder_image/{filename}?w=N: PNG ridotto cache 1h
- Frontend: 2 thumb-picker al posto dei select (thumb + nome + caret)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-24 11:10:35 +02:00
parent 2bca68d700
commit b83e577eab
47 changed files with 115 additions and 27 deletions
+19
View File
@@ -292,6 +292,25 @@ def index():
return HTMLResponse(html_path.read_text(encoding="utf-8"))
@app.get("/folder_image/{filename}")
def folder_image(filename: str, w: int = 120):
"""Serve thumbnail PNG dell'immagine IMAGES_DIR (scalata a width w)."""
if "/" in filename or ".." in filename:
raise HTTPException(400, "nome non valido")
path = IMAGES_DIR / filename
if not path.is_file():
raise HTTPException(404, "non trovato")
img = cv2.imread(str(path), cv2.IMREAD_COLOR)
if img is None:
raise HTTPException(400, "non leggibile")
h0, w0 = img.shape[:2]
if w0 > w:
sc = w / w0
img = cv2.resize(img, (w, int(h0 * sc)), interpolation=cv2.INTER_AREA)
return Response(_encode_png(img), media_type="image/png",
headers={"Cache-Control": "public, max-age=3600"})
@app.get("/images")
def list_images():
"""Lista file immagine nella cartella configurata in IMAGES_DIR."""