radiantrh/faceebene/ebenetraitementimage.php
2026-01-19 14:05:20 +00:00

175 lines
8.6 KiB
PHP
Executable File

<div class="modal fade animate__animated animate__zoomIn" id="pop_rec_faciale" tabindex="-1" role="dialog" data-bs-backdrop="static" data-bs-keyboard="false">
<div class="modal-dialog modal-lg modal-dialog-centered shadow-lg">
<div class="modal-content border-0">
<div class="modal-header bg-primary text-white py-3">
<div class="d-flex align-items-center w-100">
<div class="bg-white bg-opacity-25 p-2 rounded-circle me-3">
<i class="fas fa-face-viewfinder fa-lg text-white"></i>
</div>
<h5 class="modal-title fw-bold mb-0"><?= _("Reconnaissance Faciale") ?></h5>
<button id="btn_close_pop_rec_faciale" type="button" class="btn-close btn-close-white ms-auto" data-bs-dismiss="modal" onclick="javascript:fiche_beneficiaire();"></button>
</div>
</div>
<div class="modal-body p-4 bg-light">
<div class="row g-3 mb-4">
<div class="col-md-6">
<button id="ebene_take_photo_face" type="button" class="btn btn-primary w-100 py-3 fw-bold shadow-sm" onclick="takephoto();">
<i class="fas fa-camera me-2"></i><?= _("CAPTURER L'IMAGE") ?>
</button>
</div>
<div class="col-md-6">
<?php if ($faceRegistered == "1") : ?>
<button disabled id="ebene_confirmer_photo_face" type="button" class="btn btn-success w-100 py-3 fw-bold shadow-sm" onclick="ebene_confirmer_photo_face();">
<i class="fas fa-check-circle me-2"></i><?= _("VÉRIFIER L'IDENTITÉ") ?>
</button>
<?php else : ?>
<button disabled id="ebene_enregistrer_photo_face" type="button" class="btn btn-info text-white w-100 py-3 fw-bold shadow-sm" onclick="ebene_enregistrer_photo_face();">
<i class="fas fa-save me-2"></i><?= _("ENREGISTRER LA PHOTO") ?>
</button>
<?php endif; ?>
</div>
</div>
<div class="row g-4">
<div class="col-md-6 text-center">
<span class="badge bg-dark px-3 py-2 rounded-pill mb-2 small fw-bold text-uppercase"><?= _("Webcam en direct") ?></span>
<div class="ratio ratio-4x3 bg-dark rounded shadow-inner overflow-hidden border border-3 border-white position-relative">
<video id="video_face" autoplay playsinline class="w-100 h-100 object-fit-cover"></video>
<div class="position-absolute top-50 start-50 translate-middle border border-2 border-primary border-opacity-25 rounded-circle" style="width: 65%; height: 85%; pointer-events: none;"></div>
</div>
</div>
<div class="col-md-6 text-center">
<span class="badge bg-secondary px-3 py-2 rounded-pill mb-2 small fw-bold text-uppercase"><?= _("Capture figée") ?></span>
<div id="container_photo" class="ratio ratio-4x3 bg-white border border-3 border-white rounded shadow-inner overflow-hidden d-flex align-items-center justify-content-center position-relative">
<div id="placeholder_icon" class="position-absolute text-muted opacity-25 text-center">
<i class="fas fa-user-astronaut fa-5x"></i>
<p class="small mt-2 fw-bold text-uppercase mb-0"><?= _("En attente") ?></p>
</div>
<img id="photo_face" src="" class="w-100 h-100 object-fit-cover position-relative"
style="opacity: 0; transition: opacity 0.4s ease-in-out; z-index: 2;"
onload="this.style.opacity=1; document.getElementById('placeholder_icon').style.display='none';" />
</div>
</div>
</div>
<form id="form_face" class="visually-hidden">
<input type="hidden" id="compare_face" value="<?= $faceRegistered ?>">
<input type="hidden" id="image_face" name="image_face">
</form>
<div id="message_face" class="mt-4">
<div class="alert alert-warning mb-0 shadow-xs border-0 rounded-pill d-flex align-items-center px-4">
<i class="fas fa-info-circle me-3 text-primary"></i>
<marquee behavior="scroll" direction="left" scrollamount="3" class="small fw-bold m-0">
<?= _("Positionnez votre visage au centre du cadre pour une détection optimale.") ?>
</marquee>
</div>
</div>
<canvas id="canvas" style="display: none;"></canvas>
</div>
<div class="modal-footer bg-light border-0 p-3">
<button type="button" class="btn btn-outline-secondary fw-bold px-4 rounded-pill" data-bs-dismiss="modal" onclick="fiche_beneficiaire();">
<i class="fas fa-times me-2"></i><?= _("Fermer") ?>
</button>
</div>
</div>
</div>
</div>
<style>
/* Styles spécifiques */
#video_face { transform: scaleX(-1); } /* Effet miroir */
.object-fit-cover { object-fit: cover; }
.shadow-inner { box-shadow: inset 0 2px 8px rgba(0,0,0,0.15); }
.shadow-xs { box-shadow: 0 2px 4px rgba(0,0,0,0.05); }
.modal-content { border-radius: 1.2rem; }
/* Animation de flash lors de la capture */
.flash-effect {
animation: flash 0.4s ease-out;
}
@keyframes flash {
0% { filter: brightness(1); }
50% { filter: brightness(2); }
100% { filter: brightness(1); }
}
</style>
<script type="text/javascript">
var video = document.getElementById('video_face');
var canvas = document.getElementById('canvas');
var photo = document.getElementById('photo_face');
var image_input = document.getElementById('image_face');
var placeholder = document.getElementById('placeholder_icon');
/**
* Démarre la webcam
*/
async function initCamera() {
try {
const stream = await navigator.mediaDevices.getUserMedia({
video: { facingMode: 'user', width: 640, height: 480 },
audio: false
});
video.srcObject = stream;
} catch (err) {
console.error("Caméra inaccessible:", err);
alert("Erreur : Impossible d'accéder à la caméra.");
}
}
/**
* Prend la photo
*/
function takephoto() {
var context = canvas.getContext('2d');
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
// Capture
context.drawImage(video, 0, 0, canvas.width, canvas.height);
var data = canvas.toDataURL('image/jpeg', 0.8);
// Mise à jour de l'image (l'événement onload du HTML gère l'icône)
photo.src = data;
image_input.value = data;
// Effet visuel
document.getElementById('container_photo').classList.add('flash-effect');
setTimeout(() => document.getElementById('container_photo').classList.remove('flash-effect'), 400);
// Débloquer les boutons
var isRegistered = document.getElementById('compare_face').value;
$("#ebene_enregistrer_photo_face").prop('disabled', false);
if(isRegistered === "1") {
$("#ebene_confirmer_photo_face").prop('disabled', false);
}
}
// Gestion de la modal Bootstrap
var faceModal = document.getElementById('pop_rec_faciale');
faceModal.addEventListener('shown.bs.modal', function () {
initCamera();
});
faceModal.addEventListener('hidden.bs.modal', function () {
if (video.srcObject) {
video.srcObject.getTracks().forEach(track => track.stop());
video.srcObject = null;
}
// Reset de l'aperçu si on ferme
photo.src = "";
photo.style.opacity = 0;
placeholder.style.display = 'block';
});
</script>