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