🤖 Recadrer les photos en carré autour du visage

Nextcloud et Android affichent la photo en carré découpé au milieu
d'une photo verticale, ce qui coupe les cheveux. La photo est
désormais recadrée en carré autour du visage, détecté localement par
YuNet (OpenCV, modèle MIT versionné dans le paquet) : les yeux sont
placés à la même hauteur sur toutes les photos. Sans visage détecté,
le carré est aligné en haut et compté dans le journal (-v).

Réglages dans mapping.yaml (fields.photo.crop : eyes_at, side, ou
false). Ils entrent dans l'empreinte des seules fiches avec photo :
celles-ci seront renvoyées une fois au prochain passage.

Les tests utilisent un visage généré par thispersondoesnotexist.com
(tests/data/README.md).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
zeguiguiandClaude Opus 5.5 committed 2026-11-17 19:13:45 +01:00
1 parent 2ada724160
commit 35f90b8fb1
15 files changed
+405 -21

No files matched your search

+14
View File
@@ -1,6 +1,7 @@
from dataclasses import replace
from datetime import date
from ldap2nextcloud.config import PhotoCrop
from ldap2nextcloud.model import Contact, Email, Phone, contact_href, contact_uid, fingerprint
BASE = Contact(
@@ -51,3 +52,16 @@ def test_fingerprint_changes_with_any_field():
def test_fingerprint_changes_with_photo_settings():
assert fingerprint(BASE, 512, 80) != fingerprint(BASE, 720, 80)
assert fingerprint(BASE, 512, 80) != fingerprint(BASE, 512, 90)
def test_fingerprint_changes_with_crop_settings_when_contact_has_photo():
plain = fingerprint(BASE, 512, 80)
cropped = fingerprint(BASE, 512, 80, PhotoCrop())
assert plain != cropped
assert cropped != fingerprint(BASE, 512, 80, PhotoCrop(eyes_at=0.5))
assert cropped != fingerprint(BASE, 512, 80, PhotoCrop(side=6))
def test_crop_settings_do_not_touch_contacts_without_photo():
no_photo = replace(BASE, photo=None)
assert fingerprint(no_photo, 512, 80) == fingerprint(no_photo, 512, 80, PhotoCrop())