1 / X
const gdv_681db7687aeddcanvas = document.getElementById("gdv_681db7687aeddimageCanvas"); const gdv_681db7687aeddctx = gdv_681db7687aeddcanvas.getContext("2d");
const gdv_681db7687aeddthumbnailContainer = document.getElementById("gdv_681db7687aeddthumbnailContainer"); const gdv_681db7687aeddthumbnailContainerWrapper = document.getElementById("gdv_681db7687aeddthumbnailContainerWrapper"); const gdv_681db7687aeddzoomInButton = document.getElementById("gdv_681db7687aeddzoomIn"); const gdv_681db7687aeddzoomOutButton = document.getElementById("gdv_681db7687aeddzoomOut"); const gdv_681db7687aeddresetZoomButton = document.getElementById("gdv_681db7687aeddresetZoom");
const gdv_681db7687aeddbrightnessInput = document.getElementById("gdv_681db7687aeddbrightness"); const gdv_681db7687aeddcontrastInput = document.getElementById("gdv_681db7687aeddcontrast"); const gdv_681db7687aeddfullscreenButton = document.getElementById("gdv_681db7687aeddfullscreen");
const gdv_681db7687aeddrotateRightButton = document.getElementById("gdv_681db7687aeddrotateRight"); const gdv_681db7687aeddrotateLeftButton = document.getElementById("gdv_681db7687aeddrotateLeft");
const gdv_681db7687aeddprevSlideButton = document.getElementById("gdv_681db7687aeddprevSlide"); const gdv_681db7687aeddnextSlideButton = document.getElementById("gdv_681db7687aeddnextSlide"); const gdv_681db7687aeddslideNumberDisplay = document.getElementById("gdv_681db7687aeddslideNumber"); const gdv_681db7687aeddimageName = document.getElementById("gdv_681db7687aeddimageName");
let gdv_681db7687aeddcurrentSlideIndex = 0;
gdv_681db7687aeddbrightnessInput.addEventListener("input", gdv_681db7687aedddrawImage); gdv_681db7687aeddcontrastInput.addEventListener("input", gdv_681db7687aedddrawImage);
const gdv_681db7687aeddimageUrls = [{"url":"https:\/\/drive.google.com\/thumbnail?id=1dfbuPTOdmMnyRG-9Ze6ShpQndSJxiXGe&sz=w3000","name":"EPOL_ordre d'arrestation de Rollain, Cotelle et Esnault.jpg"}];
let gdv_681db7687aeddscale = 1; let gdv_681db7687aeddoriginX = 0; let gdv_681db7687aeddoriginY = 0; const gdv_681db7687aeddminScale = 0.1; const gdv_681db7687aeddmaxScale = 5; let gdv_681db7687aeddcurrentImage = new Image();
let gdv_681db7687aeddrotationAngle = 0;
gdv_681db7687aeddrotateRightButton.addEventListener("click", function() { gdv_681db7687aeddrotationAngle = (gdv_681db7687aeddrotationAngle + 90) % 360; gdv_681db7687aedddrawImage(); });
gdv_681db7687aeddrotateLeftButton.addEventListener("click", function() { gdv_681db7687aeddrotationAngle = (gdv_681db7687aeddrotationAngle - 90 + 360) % 360; gdv_681db7687aedddrawImage(); });
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_681db7687aeddcurrentImage.src = gdv_681db7687aeddimageUrls[0]["url"]; gdv_681db7687aeddimageName.innerHTML = filtrerChaine(gdv_681db7687aeddimageUrls[0]["name"], "rien"); gdv_681db7687aeddcurrentImage.onload = function() {
gdv_681db7687aeddupdateSlideNumber(); gdv_681db7687aeddresizeCanvas(); gdv_681db7687aedddrawImage(); document.getElementById("gdv_681db7687aeddcontrols").style.display = "block"; };
function gdv_681db7687aeddupdateSlideNumber() { gdv_681db7687aeddslideNumberDisplay.textContent = `${gdv_681db7687aeddcurrentSlideIndex + 1} / ${gdv_681db7687aeddimageUrls.length}`; }
gdv_681db7687aeddprevSlideButton.addEventListener("click", function() { if (gdv_681db7687aeddcurrentSlideIndex > 0) { gdv_681db7687aeddcurrentSlideIndex--; gdv_681db7687aeddloadImage(gdv_681db7687aeddcurrentSlideIndex); gdv_681db7687aeddupdateSlideNumber(); } });
gdv_681db7687aeddnextSlideButton.addEventListener("click", function() { if (gdv_681db7687aeddcurrentSlideIndex < gdv_681db7687aeddimageUrls.length - 1) { gdv_681db7687aeddcurrentSlideIndex++; gdv_681db7687aeddloadImage(gdv_681db7687aeddcurrentSlideIndex); gdv_681db7687aeddupdateSlideNumber(); } }); function gdv_681db7687aeddresizeCanvas() { // Ajuster la taille du canvas pour correspondre à celle du conteneur const container = document.getElementById("gdv_681db7687aeddcanvasContainer"); gdv_681db7687aeddcanvas.width = container.clientWidth; gdv_681db7687aeddcanvas.height = container.clientHeight - 30; gdv_681db7687aeddfitImageToCanvas(); // Redessiner le contenu du canvas ici gdv_681db7687aedddrawImage(); } window.addEventListener("load", gdv_681db7687aeddresizeCanvas); window.addEventListener("resize", gdv_681db7687aeddresizeCanvas); function gdv_681db7687aeddfitImageToCanvas() { const canvasAspect = gdv_681db7687aeddcanvas.width / gdv_681db7687aeddcanvas.height; const imageAspect = gdv_681db7687aeddcurrentImage.width / gdv_681db7687aeddcurrentImage.height; if (imageAspect > canvasAspect) { gdv_681db7687aeddscale = gdv_681db7687aeddcanvas.width / gdv_681db7687aeddcurrentImage.width; } else { gdv_681db7687aeddscale = gdv_681db7687aeddcanvas.height / gdv_681db7687aeddcurrentImage.height; } gdv_681db7687aeddoriginX = gdv_681db7687aeddcanvas.width / 2; gdv_681db7687aeddoriginY = gdv_681db7687aeddcanvas.height / 2; }
function gdv_681db7687aedddrawImage() { gdv_681db7687aeddctx.clearRect(0, 0, gdv_681db7687aeddcanvas.width, gdv_681db7687aeddcanvas.height); gdv_681db7687aeddctx.save(); gdv_681db7687aeddctx.translate(gdv_681db7687aeddoriginX, gdv_681db7687aeddoriginY); gdv_681db7687aeddctx.rotate((Math.PI / 180) * gdv_681db7687aeddrotationAngle); gdv_681db7687aeddctx.scale(gdv_681db7687aeddscale, gdv_681db7687aeddscale);
// Appliquer la luminosité et le contraste gdv_681db7687aeddctx.filter = `brightness(${gdv_681db7687aeddbrightnessInput.value}) contrast(${gdv_681db7687aeddcontrastInput.value})`; gdv_681db7687aeddctx.drawImage(gdv_681db7687aeddcurrentImage, -gdv_681db7687aeddcurrentImage.width/2, -gdv_681db7687aeddcurrentImage.height/2); gdv_681db7687aeddctx.restore(); }
// Ajouter les miniatures des images gdv_681db7687aeddimageUrls.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_681db7687aeddloadImage(index); gdv_681db7687aeddcurrentSlideIndex = index; gdv_681db7687aeddupdateSlideNumber(); }; slide.appendChild(img); gdv_681db7687aeddthumbnailContainerWrapper.appendChild(slide); });
// Charger une image dans le canvas function gdv_681db7687aeddloadImage(index) { gdv_681db7687aeddcurrentImage.src = gdv_681db7687aeddimageUrls[index]["url"]; gdv_681db7687aeddimageName.innerHTML = filtrerChaine(gdv_681db7687aeddimageUrls[index]["name"], "rien"); gdv_681db7687aeddcurrentImage.onload = function() { gdv_681db7687aeddscale = 1; gdv_681db7687aeddoriginX = 0; gdv_681db7687aeddoriginY = 0; gdv_681db7687aeddfitImageToCanvas(); gdv_681db7687aedddrawImage(); }; }
// Initialiser Swiper var gdv_681db7687aeddswiper = new Swiper(".gdv_681db7687aeddswiper-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, });
//gdv_681db7687aeddswiper.on("slideChange", function () { // gdv_681db7687aeddcurrentSlideIndex = gdv_681db7687aeddswiper.activeIndex; // gdv_681db7687aeddupdateSlideNumber(); //});
// Plein écran gdv_681db7687aeddfullscreenButton.addEventListener("click", function() { if (!document.fullscreenElement) { document.getElementById("gdv_681db7687aeddgd-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_681db7687aeddcanvas.addEventListener("wheel", function(event) { event.preventDefault(); const zoomFactor = 0.025; const mouseX = event.offsetX; const mouseY = event.offsetY;
let newScale = gdv_681db7687aeddscale; if (event.deltaY < 0) { newScale *= 1 + zoomFactor; } else { newScale /= 1 + zoomFactor; } newScale = Math.max(gdv_681db7687aeddminScale, Math.min(gdv_681db7687aeddmaxScale, newScale)); const scaleRatio = newScale / gdv_681db7687aeddscale; gdv_681db7687aeddoriginX = mouseX - (mouseX - gdv_681db7687aeddoriginX) * scaleRatio; gdv_681db7687aeddoriginY = mouseY - (mouseY - gdv_681db7687aeddoriginY) * scaleRatio; gdv_681db7687aeddscale = newScale; gdv_681db7687aedddrawImage(); }); // Gestion du déplacement (pan) let gdv_681db7687aeddisDragging = false; let gdv_681db7687aeddstartX, gdv_681db7687aeddstartY; gdv_681db7687aeddcanvas.addEventListener("mousedown", function(event) { gdv_681db7687aeddisDragging = true; gdv_681db7687aeddstartX = event.offsetX - gdv_681db7687aeddoriginX; gdv_681db7687aeddstartY = event.offsetY - gdv_681db7687aeddoriginY; gdv_681db7687aeddcanvas.style.cursor = "grabbing"; }); gdv_681db7687aeddcanvas.addEventListener("mousemove", function(event) { if (gdv_681db7687aeddisDragging) { gdv_681db7687aeddoriginX = event.offsetX - gdv_681db7687aeddstartX; gdv_681db7687aeddoriginY = event.offsetY - gdv_681db7687aeddstartY; gdv_681db7687aedddrawImage(); } }); // Gestion des événements tactiles gdv_681db7687aeddcanvas.addEventListener("touchstart", function(event) { if (event.touches.length === 1) { gdv_681db7687aeddisDragging = true; const touch = event.touches[0]; gdv_681db7687aeddstartX = touch.pageX - gdv_681db7687aeddoriginX; gdv_681db7687aeddstartY = touch.pageY - gdv_681db7687aeddoriginY; } }); gdv_681db7687aeddcanvas.addEventListener("touchmove", function(event) { event.preventDefault(); // Empêche le comportement par défaut du navigateur const touch = event.touches[0]; gdv_681db7687aeddoriginX = touch.pageX - gdv_681db7687aeddstartX; gdv_681db7687aeddoriginY = touch.pageY - gdv_681db7687aeddstartY; gdv_681db7687aedddrawImage(); }); gdv_681db7687aeddcanvas.addEventListener("touchend", function() { gdv_681db7687aeddisDragging = false; }); gdv_681db7687aeddcanvas.addEventListener("mouseup", function() { gdv_681db7687aeddisDragging = false; gdv_681db7687aeddcanvas.style.cursor = "grab"; }); gdv_681db7687aeddcanvas.addEventListener("mouseleave", function() { gdv_681db7687aeddisDragging = false; gdv_681db7687aeddcanvas.style.cursor = "grab"; }); gdv_681db7687aeddzoomInButton.addEventListener("click", function() { let newScale = gdv_681db7687aeddscale; const zoomFactor = 0.025; newScale *= 1 + zoomFactor; gdv_681db7687aeddscale = Math.max(gdv_681db7687aeddminScale, Math.min(gdv_681db7687aeddmaxScale, newScale)); gdv_681db7687aedddrawImage(); }); gdv_681db7687aeddzoomOutButton.addEventListener("click", function() { let newScale = gdv_681db7687aeddscale; const zoomFactor = 0.025; newScale /= 1 + zoomFactor; gdv_681db7687aeddscale = Math.max(gdv_681db7687aeddminScale, Math.min(gdv_681db7687aeddmaxScale, newScale)); gdv_681db7687aedddrawImage(); }); gdv_681db7687aeddresetZoomButton.addEventListener("click", function() { gdv_681db7687aeddrotationAngle = 0; gdv_681db7687aeddfitImageToCanvas(); gdv_681db7687aedddrawImage(); }); function gdv_681db7687aeddgetImageIdFromUrl(url) { const urlObj = new URL(url); return urlObj.searchParams.get("id"); } document.getElementById("gdv_681db7687aedddownloadImage").addEventListener("click", function() { let url = gdv_681db7687aeddcurrentImage.src; const imageId = gdv_681db7687aeddgetImageIdFromUrl(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_681db7687aeddprintImageFromApi(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_681db7687aeddprintButton = document.getElementById("gdv_681db7687aeddprintCanvas");
gdv_681db7687aeddprintButton.addEventListener("click", function() { let url = gdv_681db7687aeddcurrentImage.src; const imageId = gdv_681db7687aeddgetImageIdFromUrl(url); gdv_681db7687aeddprintImageFromApi(imageId); });
let gdv_681db7687aeddinitialDistance = 0; let gdv_681db7687aeddinitialScale = 1;
gdv_681db7687aeddcanvas.addEventListener("touchstart", function(event) { if (event.touches.length === 2) { event.preventDefault(); gdv_681db7687aeddinitialDistance = getDistance(event.touches[0], event.touches[1]); gdv_681db7687aeddinitialScale = gdv_681db7687aeddscale; } });
gdv_681db7687aeddcanvas.addEventListener("touchmove", function(event) { if (event.touches.length === 2) { event.preventDefault(); const currentDistance = getDistance(event.touches[0], event.touches[1]); const scaleChange = currentDistance / gdv_681db7687aeddinitialDistance; let newScale = gdv_681db7687aeddinitialScale * scaleChange;
newScale = Math.max(gdv_681db7687aeddminScale, Math.min(gdv_681db7687aeddmaxScale, 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_681db7687aeddscale; gdv_681db7687aeddoriginX = centerX - (centerX - gdv_681db7687aeddoriginX) * scaleRatio; gdv_681db7687aeddoriginY = centerY - (centerY - gdv_681db7687aeddoriginY) * scaleRatio;
gdv_681db7687aeddscale = newScale; gdv_681db7687aedddrawImage(); // 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); }