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) <noreply@anthropic.com>
This commit is contained in:
2026-04-07 19:29:31 +02:00
parent 79b0084178
commit 3c308085af

View File

@@ -146,6 +146,8 @@ class Camera:
return self._capture_simulation(chemin_dest) return self._capture_simulation(chemin_dest)
def _capture_gphoto2(self, chemin_dest: Path) -> Path | None: def _capture_gphoto2(self, chemin_dest: Path) -> Path | None:
from PIL import Image as PILImage
for attempt in range(3): for attempt in range(3):
try: try:
chemin_camera = self.camera.capture(gp.GP_CAPTURE_IMAGE) chemin_camera = self.camera.capture(gp.GP_CAPTURE_IMAGE)
@@ -153,8 +155,19 @@ class Camera:
self.camera.file_get( self.camera.file_get(
chemin_camera.folder, chemin_camera.name, gp.GP_FILE_TYPE_NORMAL, fichier_camera chemin_camera.folder, chemin_camera.name, gp.GP_FILE_TYPE_NORMAL, fichier_camera
) )
fichier_camera.save(str(chemin_dest)) # Sauvegarder le fichier brut temporairement
log.info(f"Photo capturee (DSLR) : {chemin_dest}") 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 return chemin_dest
except gp.GPhoto2Error as e: except gp.GPhoto2Error as e:
if "I/O in progress" in str(e) and attempt < 2: if "I/O in progress" in str(e) and attempt < 2: