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:
@@ -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."""
|
||||
|
||||
Reference in New Issue
Block a user