1 / X
const gdv_699248bfb4ae5canvas = document.getElementById("gdv_699248bfb4ae5imageCanvas"); const gdv_699248bfb4ae5ctx = gdv_699248bfb4ae5canvas.getContext("2d");
const gdv_699248bfb4ae5thumbnailContainer = document.getElementById("gdv_699248bfb4ae5thumbnailContainer"); const gdv_699248bfb4ae5thumbnailContainerWrapper = document.getElementById("gdv_699248bfb4ae5thumbnailContainerWrapper"); const gdv_699248bfb4ae5zoomInButton = document.getElementById("gdv_699248bfb4ae5zoomIn"); const gdv_699248bfb4ae5zoomOutButton = document.getElementById("gdv_699248bfb4ae5zoomOut"); const gdv_699248bfb4ae5resetZoomButton = document.getElementById("gdv_699248bfb4ae5resetZoom");
const gdv_699248bfb4ae5brightnessInput = document.getElementById("gdv_699248bfb4ae5brightness"); const gdv_699248bfb4ae5contrastInput = document.getElementById("gdv_699248bfb4ae5contrast"); const gdv_699248bfb4ae5fullscreenButton = document.getElementById("gdv_699248bfb4ae5fullscreen");
const gdv_699248bfb4ae5rotateRightButton = document.getElementById("gdv_699248bfb4ae5rotateRight"); const gdv_699248bfb4ae5rotateLeftButton = document.getElementById("gdv_699248bfb4ae5rotateLeft");
const gdv_699248bfb4ae5prevSlideButton = document.getElementById("gdv_699248bfb4ae5prevSlide"); const gdv_699248bfb4ae5nextSlideButton = document.getElementById("gdv_699248bfb4ae5nextSlide"); const gdv_699248bfb4ae5slideNumberDisplay = document.getElementById("gdv_699248bfb4ae5slideNumber"); const gdv_699248bfb4ae5imageName = document.getElementById("gdv_699248bfb4ae5imageName");
let gdv_699248bfb4ae5currentSlideIndex = 0;
gdv_699248bfb4ae5brightnessInput.addEventListener("input", gdv_699248bfb4ae5drawImage); gdv_699248bfb4ae5contrastInput.addEventListener("input", gdv_699248bfb4ae5drawImage);
const gdv_699248bfb4ae5imageUrls = [{"url":"https:\/\/drive.google.com\/thumbnail?id=140TrarVi8qymToFqN6L6uclHXh7mJnvG&sz=w3000","name":"EPOL_Supension de plusieurs fonctionnaires.jpg"}];
let gdv_699248bfb4ae5scale = 1; let gdv_699248bfb4ae5originX = 0; let gdv_699248bfb4ae5originY = 0; const gdv_699248bfb4ae5minScale = 0.1; const gdv_699248bfb4ae5maxScale = 5; let gdv_699248bfb4ae5currentImage = new Image();
let gdv_699248bfb4ae5rotationAngle = 0;
gdv_699248bfb4ae5rotateRightButton.addEventListener("click", function() { gdv_699248bfb4ae5rotationAngle = (gdv_699248bfb4ae5rotationAngle + 90) % 360; gdv_699248bfb4ae5drawImage(); });
gdv_699248bfb4ae5rotateLeftButton.addEventListener("click", function() { gdv_699248bfb4ae5rotationAngle = (gdv_699248bfb4ae5rotationAngle - 90 + 360) % 360; gdv_699248bfb4ae5drawImage(); });
function filtrerChaine(texte, cacher) { if (!texte) return "";
switch (cacher) { case "chiffre": return texte.replace(/\d/g, "");
case "tout": return "";
case "vide": default: return texte; } }
// Charger la première image par défaut gdv_699248bfb4ae5currentImage.src = gdv_699248bfb4ae5imageUrls[0]["url"]; gdv_699248bfb4ae5imageName.innerHTML = filtrerChaine(gdv_699248bfb4ae5imageUrls[0]["name"], "rien"); gdv_699248bfb4ae5currentImage.onload = function() {
gdv_699248bfb4ae5updateSlideNumber(); gdv_699248bfb4ae5resizeCanvas(); gdv_699248bfb4ae5drawImage(); document.getElementById("gdv_699248bfb4ae5controls").style.display = "block"; };
function gdv_699248bfb4ae5updateSlideNumber() { gdv_699248bfb4ae5slideNumberDisplay.textContent = `${gdv_699248bfb4ae5currentSlideIndex + 1} / ${gdv_699248bfb4ae5imageUrls.length}`; }
gdv_699248bfb4ae5prevSlideButton.addEventListener("click", function() { if (gdv_699248bfb4ae5currentSlideIndex > 0) { gdv_699248bfb4ae5currentSlideIndex--; gdv_699248bfb4ae5loadImage(gdv_699248bfb4ae5currentSlideIndex); gdv_699248bfb4ae5updateSlideNumber(); } });
gdv_699248bfb4ae5nextSlideButton.addEventListener("click", function() { if (gdv_699248bfb4ae5currentSlideIndex < gdv_699248bfb4ae5imageUrls.length - 1) { gdv_699248bfb4ae5currentSlideIndex++; gdv_699248bfb4ae5loadImage(gdv_699248bfb4ae5currentSlideIndex); gdv_699248bfb4ae5updateSlideNumber(); } }); function gdv_699248bfb4ae5resizeCanvas() { // Ajuster la taille du canvas pour correspondre à celle du conteneur const container = document.getElementById("gdv_699248bfb4ae5canvasContainer"); gdv_699248bfb4ae5canvas.width = container.clientWidth; gdv_699248bfb4ae5canvas.height = container.clientHeight - 30; gdv_699248bfb4ae5fitImageToCanvas(); // Redessiner le contenu du canvas ici gdv_699248bfb4ae5drawImage(); } window.addEventListener("load", gdv_699248bfb4ae5resizeCanvas); window.addEventListener("resize", gdv_699248bfb4ae5resizeCanvas); function gdv_699248bfb4ae5fitImageToCanvas() { const canvasAspect = gdv_699248bfb4ae5canvas.width / gdv_699248bfb4ae5canvas.height; const imageAspect = gdv_699248bfb4ae5currentImage.width / gdv_699248bfb4ae5currentImage.height; if (imageAspect > canvasAspect) { gdv_699248bfb4ae5scale = gdv_699248bfb4ae5canvas.width / gdv_699248bfb4ae5currentImage.width; } else { gdv_699248bfb4ae5scale = gdv_699248bfb4ae5canvas.height / gdv_699248bfb4ae5currentImage.height; } gdv_699248bfb4ae5originX = gdv_699248bfb4ae5canvas.width / 2; gdv_699248bfb4ae5originY = gdv_699248bfb4ae5canvas.height / 2; }
function gdv_699248bfb4ae5drawImage() { gdv_699248bfb4ae5ctx.clearRect(0, 0, gdv_699248bfb4ae5canvas.width, gdv_699248bfb4ae5canvas.height); gdv_699248bfb4ae5ctx.save(); gdv_699248bfb4ae5ctx.translate(gdv_699248bfb4ae5originX, gdv_699248bfb4ae5originY); gdv_699248bfb4ae5ctx.rotate((Math.PI / 180) * gdv_699248bfb4ae5rotationAngle); gdv_699248bfb4ae5ctx.scale(gdv_699248bfb4ae5scale, gdv_699248bfb4ae5scale);
// Appliquer la luminosité et le contraste gdv_699248bfb4ae5ctx.filter = `brightness(${gdv_699248bfb4ae5brightnessInput.value}) contrast(${gdv_699248bfb4ae5contrastInput.value})`; gdv_699248bfb4ae5ctx.drawImage(gdv_699248bfb4ae5currentImage, -gdv_699248bfb4ae5currentImage.width/2, -gdv_699248bfb4ae5currentImage.height/2); gdv_699248bfb4ae5ctx.restore(); }
// Ajouter les miniatures des images gdv_699248bfb4ae5imageUrls.forEach((obj, index) => { const slide = document.createElement("div"); slide.classList.add("swiper-slide"); const img = new Image(); img.loading = "lazy"; img.src = obj["url"]; img.onclick = function() { gdv_699248bfb4ae5loadImage(index); gdv_699248bfb4ae5currentSlideIndex = index; gdv_699248bfb4ae5updateSlideNumber(); }; slide.appendChild(img); gdv_699248bfb4ae5thumbnailContainerWrapper.appendChild(slide); });
// Charger une image dans le canvas function gdv_699248bfb4ae5loadImage(index) { gdv_699248bfb4ae5currentImage.src = gdv_699248bfb4ae5imageUrls[index]["url"]; gdv_699248bfb4ae5imageName.innerHTML = filtrerChaine(gdv_699248bfb4ae5imageUrls[index]["name"], "rien"); gdv_699248bfb4ae5currentImage.onload = function() { gdv_699248bfb4ae5scale = 1; gdv_699248bfb4ae5originX = 0; gdv_699248bfb4ae5originY = 0; gdv_699248bfb4ae5fitImageToCanvas(); gdv_699248bfb4ae5drawImage(); };
const thumbnails = document.querySelectorAll(".swiper-slide"); thumbnails.forEach((thumb, i) => { if (i === index) { thumb.classList.add("active-thumbnail"); } else { thumb.classList.remove("active-thumbnail"); } }); }
// Initialiser Swiper var gdv_699248bfb4ae5swiper = new Swiper(".gdv_699248bfb4ae5swiper-container", { direction: "horizontal", slidesPerView: 8, spaceBetween: 5, breakpoints: { 576: { slidesPerView: 8, spaceBetween: 5 }, 768: { slidesPerView: 9, spaceBetween: 5 }, 992: { slidesPerView: 11, spaceBetween: 5 }, 1200: { slidesPerView: 13, spaceBetween: 5 } }, mousewheel: true, });
document.querySelector(".swiper-slide").classList.add("active-thumbnail");
//gdv_699248bfb4ae5swiper.on("slideChange", function () { // gdv_699248bfb4ae5currentSlideIndex = gdv_699248bfb4ae5swiper.activeIndex; // gdv_699248bfb4ae5updateSlideNumber(); //});
// Plein écran gdv_699248bfb4ae5fullscreenButton.addEventListener("click", function() { if (!document.fullscreenElement) { document.getElementById("gdv_699248bfb4ae5gd-image-gallery").requestFullscreen().catch(err => { alert(`Erreur lors de la tentative de mise en plein écran: ${err.message}`); }); } else { document.exitFullscreen(); } });
// Impression du canvas
/*printButton.addEventListener("click", function() {
const dataUrl = canvas.toDataURL();
const windowContent = ``;
const printWindow = window.open("", "", "width=800,height=800");
printWindow.document.write(windowContent);
printWindow.document.close();
});
*/
// Gestion du zoom gdv_699248bfb4ae5canvas.addEventListener("wheel", function(event) { event.preventDefault(); const zoomFactor = 0.025; const mouseX = event.offsetX; const mouseY = event.offsetY;
let newScale = gdv_699248bfb4ae5scale; if (event.deltaY < 0) { newScale *= 1 + zoomFactor; } else { newScale /= 1 + zoomFactor; } newScale = Math.max(gdv_699248bfb4ae5minScale, Math.min(gdv_699248bfb4ae5maxScale, newScale)); const scaleRatio = newScale / gdv_699248bfb4ae5scale; gdv_699248bfb4ae5originX = mouseX - (mouseX - gdv_699248bfb4ae5originX) * scaleRatio; gdv_699248bfb4ae5originY = mouseY - (mouseY - gdv_699248bfb4ae5originY) * scaleRatio; gdv_699248bfb4ae5scale = newScale; gdv_699248bfb4ae5drawImage(); }); // Gestion du déplacement (pan) let gdv_699248bfb4ae5isDragging = false; let gdv_699248bfb4ae5startX, gdv_699248bfb4ae5startY; gdv_699248bfb4ae5canvas.addEventListener("mousedown", function(event) { gdv_699248bfb4ae5isDragging = true; gdv_699248bfb4ae5startX = event.offsetX - gdv_699248bfb4ae5originX; gdv_699248bfb4ae5startY = event.offsetY - gdv_699248bfb4ae5originY; gdv_699248bfb4ae5canvas.style.cursor = "grabbing"; }); gdv_699248bfb4ae5canvas.addEventListener("mousemove", function(event) { if (gdv_699248bfb4ae5isDragging) { gdv_699248bfb4ae5originX = event.offsetX - gdv_699248bfb4ae5startX; gdv_699248bfb4ae5originY = event.offsetY - gdv_699248bfb4ae5startY; gdv_699248bfb4ae5drawImage(); } }); // Gestion des événements tactiles gdv_699248bfb4ae5canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 1) { gdv_699248bfb4ae5isDragging = true; const touch = event.touches[0]; gdv_699248bfb4ae5startX = touch.pageX - gdv_699248bfb4ae5originX; gdv_699248bfb4ae5startY = touch.pageY - gdv_699248bfb4ae5originY; } }); gdv_699248bfb4ae5canvas.addEventListener("touchmove", function(event) { event.preventDefault(); // Empêche le comportement par défaut du navigateur const touch = event.touches[0]; gdv_699248bfb4ae5originX = touch.pageX - gdv_699248bfb4ae5startX; gdv_699248bfb4ae5originY = touch.pageY - gdv_699248bfb4ae5startY; gdv_699248bfb4ae5drawImage(); }); gdv_699248bfb4ae5canvas.addEventListener("touchend", function() { gdv_699248bfb4ae5isDragging = false; }); gdv_699248bfb4ae5canvas.addEventListener("mouseup", function() { gdv_699248bfb4ae5isDragging = false; gdv_699248bfb4ae5canvas.style.cursor = "grab"; }); gdv_699248bfb4ae5canvas.addEventListener("mouseleave", function() { gdv_699248bfb4ae5isDragging = false; gdv_699248bfb4ae5canvas.style.cursor = "grab"; }); gdv_699248bfb4ae5zoomInButton.addEventListener("click", function() { let newScale = gdv_699248bfb4ae5scale; const zoomFactor = 0.025; newScale *= 1 + zoomFactor; gdv_699248bfb4ae5scale = Math.max(gdv_699248bfb4ae5minScale, Math.min(gdv_699248bfb4ae5maxScale, newScale)); gdv_699248bfb4ae5drawImage(); }); gdv_699248bfb4ae5zoomOutButton.addEventListener("click", function() { let newScale = gdv_699248bfb4ae5scale; const zoomFactor = 0.025; newScale /= 1 + zoomFactor; gdv_699248bfb4ae5scale = Math.max(gdv_699248bfb4ae5minScale, Math.min(gdv_699248bfb4ae5maxScale, newScale)); gdv_699248bfb4ae5drawImage(); }); gdv_699248bfb4ae5resetZoomButton.addEventListener("click", function() { gdv_699248bfb4ae5rotationAngle = 0; gdv_699248bfb4ae5fitImageToCanvas(); gdv_699248bfb4ae5drawImage(); }); function gdv_699248bfb4ae5getImageIdFromUrl(url) { const urlObj = new URL(url); return urlObj.searchParams.get("id"); } document.getElementById("gdv_699248bfb4ae5downloadImage").addEventListener("click", function() { let url = gdv_699248bfb4ae5currentImage.src; const imageId = gdv_699248bfb4ae5getImageIdFromUrl(url); const apiUrl = `${window.location.origin}/wp-json/gdv/v1/download-image?image_id=${imageId}`; fetch(apiUrl) .then(response => response.blob()) .then(blob => { const url = window.URL.createObjectURL(blob); const a = document.createElement("a"); a.style.display = "none"; a.href = url; a.download = `${imageId}.jpg`; document.body.appendChild(a); a.click(); window.URL.revokeObjectURL(url); }) .catch(error => console.error("Error downloading image:", error)); });
function gdv_699248bfb4ae5printImageFromApi(imageId) { const apiUrl = `${window.location.origin}/wp-json/gdv/v1/download-image?image_id=${imageId}`;
fetch(apiUrl) .then(response => response.blob()) .then(blob => { const url = URL.createObjectURL(blob); const printWindow = window.open("", "_blank"); printWindow.document.write(`
const gdv_699248bfb4ae5printButton = document.getElementById("gdv_699248bfb4ae5printCanvas");
gdv_699248bfb4ae5printButton.addEventListener("click", function() { let url = gdv_699248bfb4ae5currentImage.src; const imageId = gdv_699248bfb4ae5getImageIdFromUrl(url); gdv_699248bfb4ae5printImageFromApi(imageId); });
let gdv_699248bfb4ae5initialDistance = 0; let gdv_699248bfb4ae5initialScale = 1;
gdv_699248bfb4ae5canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 2) { event.preventDefault(); gdv_699248bfb4ae5initialDistance = getDistance(event.touches[0], event.touches[1]); gdv_699248bfb4ae5initialScale = gdv_699248bfb4ae5scale; } });
gdv_699248bfb4ae5canvas.addEventListener("touchmove", function(event) { if (event.touches.length === 2) { event.preventDefault(); const currentDistance = getDistance(event.touches[0], event.touches[1]); const scaleChange = currentDistance / gdv_699248bfb4ae5initialDistance; let newScale = gdv_699248bfb4ae5initialScale * scaleChange;
newScale = Math.max(gdv_699248bfb4ae5minScale, Math.min(gdv_699248bfb4ae5maxScale, newScale));
const centerX = (event.touches[0].pageX + event.touches[1].pageX) / 2; const centerY = (event.touches[0].pageY + event.touches[1].pageY) / 2;
const scaleRatio = newScale / gdv_699248bfb4ae5scale; gdv_699248bfb4ae5originX = centerX - (centerX - gdv_699248bfb4ae5originX) * scaleRatio; gdv_699248bfb4ae5originY = centerY - (centerY - gdv_699248bfb4ae5originY) * scaleRatio;
gdv_699248bfb4ae5scale = newScale; gdv_699248bfb4ae5drawImage(); // Remplacez par votre fonction de dessin } });
function getDistance(touch1, touch2) { const dx = touch2.pageX - touch1.pageX; const dy = touch2.pageY - touch1.pageY; return Math.sqrt(dx * dx + dy * dy); }