From 3c308085af175561dd8490fe585601ac59360d75 Mon Sep 17 00:00:00 2001 From: Jules Date: Tue, 7 Apr 2026 19:29:31 +0200 Subject: [PATCH] Redimensionner photos DSLR (max 3000px, JPEG 92%) pour affichage rapide Les RAW du Canon 6D font 24Mo, trop lent pour le navigateur. Co-Authored-By: Claude Opus 4.6 (1M context) --- backend/camera.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/backend/camera.py b/backend/camera.py index d6faaee..c51166b 100644 --- a/backend/camera.py +++ b/backend/camera.py @@ -146,6 +146,8 @@ class Camera: return self._capture_simulation(chemin_dest) def _capture_gphoto2(self, chemin_dest: Path) -> Path | None: + from PIL import Image as PILImage + for attempt in range(3): try: chemin_camera = self.camera.capture(gp.GP_CAPTURE_IMAGE) @@ -153,8 +155,19 @@ class Camera: self.camera.file_get( chemin_camera.folder, chemin_camera.name, gp.GP_FILE_TYPE_NORMAL, fichier_camera ) - fichier_camera.save(str(chemin_dest)) - log.info(f"Photo capturee (DSLR) : {chemin_dest}") + # Sauvegarder le fichier brut temporairement + tmp_path = str(chemin_dest) + ".tmp" + fichier_camera.save(tmp_path) + + # Redimensionner si trop gros (max 3000px de large, JPEG 92%) + img = PILImage.open(tmp_path) + if img.width > 3000: + ratio = 3000 / img.width + img = img.resize((3000, int(img.height * ratio)), PILImage.LANCZOS) + img.save(str(chemin_dest), "JPEG", quality=92) + Path(tmp_path).unlink(missing_ok=True) + + log.info(f"Photo capturee (DSLR) : {chemin_dest} ({img.width}x{img.height})") return chemin_dest except gp.GPhoto2Error as e: if "I/O in progress" in str(e) and attempt < 2: