diff --git a/backend/printer.py b/backend/printer.py index 710d9ae..46d2946 100644 --- a/backend/printer.py +++ b/backend/printer.py @@ -79,7 +79,8 @@ def _crop_to(img, largeur: int, hauteur: int): def _preparer_image(chemin: Path, largeur: int, hauteur: int, format_papier: str | None = None, cadre: str | None = None, - orientation: str = "paysage", event_id: str | None = None) -> Path: + orientation: str = "paysage", event_id: str | None = None, + skip_rotate: bool = False) -> Path: """ Pivote si nécessaire, recadre aux dimensions exactes (cover crop), applique le cadre, compense les marges de coupe, sauvegarde en temp. @@ -93,10 +94,11 @@ def _preparer_image(chemin: Path, largeur: int, hauteur: int, img = Image.open(chemin).convert("RGB") img = ImageOps.exif_transpose(img) - if orientation == "portrait" and img.width > img.height: - img = img.rotate(90, expand=True) - elif orientation == "paysage" and img.height > img.width: - img = img.rotate(-90, expand=True) + if not skip_rotate: + if orientation == "portrait" and img.width > img.height: + img = img.rotate(90, expand=True) + elif orientation == "paysage" and img.height > img.width: + img = img.rotate(-90, expand=True) img = _crop_to(img, largeur, hauteur) @@ -106,7 +108,7 @@ def _preparer_image(chemin: Path, largeur: int, hauteur: int, img = _appliquer_offsets_coupe(img) config_imp = charger_config().get("impression", {}) - if config_imp.get("rotation_180", False): + if config_imp.get("rotation_180", False) and not skip_rotate: img = img.rotate(180) tmp = tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) @@ -260,7 +262,7 @@ def imprimer( fmt_base = format_papier.replace("-2up", "") is_strip = "-2up" in format_papier cadre = cadre_override if cadre_override is not None else (None if is_strip else conf_imp.get("cadres_actifs", {}).get(fmt_base)) - orientation = conf_imp.get("orientations", {}).get(fmt_base, "portrait") + orientation = "portrait" if is_strip else conf_imp.get("orientations", {}).get(fmt_base, "portrait") if orientation == "paysage" and hauteur > largeur: largeur, hauteur = hauteur, largeur @@ -278,7 +280,7 @@ def imprimer( log.error(f"Fichier introuvable : {chemin_photo}") return {"succes": False, "erreur": ERREUR_FICHIER, "message": "Fichier photo introuvable"} - chemin_print = _preparer_image(chemin_photo, largeur, hauteur, fmt_base, cadre, orientation, event_id=event_id) + chemin_print = _preparer_image(chemin_photo, largeur, hauteur, fmt_base, cadre, orientation, event_id=event_id, skip_rotate=is_strip) tmp_a_supprimer = [chemin_print] if chemin_print != chemin_photo else [] px_page = fmt.get("px_page")