1 / X
const gdv_697184f9ac3cfcanvas = document.getElementById("gdv_697184f9ac3cfimageCanvas"); const gdv_697184f9ac3cfctx = gdv_697184f9ac3cfcanvas.getContext("2d");
const gdv_697184f9ac3cfthumbnailContainer = document.getElementById("gdv_697184f9ac3cfthumbnailContainer"); const gdv_697184f9ac3cfthumbnailContainerWrapper = document.getElementById("gdv_697184f9ac3cfthumbnailContainerWrapper"); const gdv_697184f9ac3cfzoomInButton = document.getElementById("gdv_697184f9ac3cfzoomIn"); const gdv_697184f9ac3cfzoomOutButton = document.getElementById("gdv_697184f9ac3cfzoomOut"); const gdv_697184f9ac3cfresetZoomButton = document.getElementById("gdv_697184f9ac3cfresetZoom");
const gdv_697184f9ac3cfbrightnessInput = document.getElementById("gdv_697184f9ac3cfbrightness"); const gdv_697184f9ac3cfcontrastInput = document.getElementById("gdv_697184f9ac3cfcontrast"); const gdv_697184f9ac3cffullscreenButton = document.getElementById("gdv_697184f9ac3cffullscreen");
const gdv_697184f9ac3cfrotateRightButton = document.getElementById("gdv_697184f9ac3cfrotateRight"); const gdv_697184f9ac3cfrotateLeftButton = document.getElementById("gdv_697184f9ac3cfrotateLeft");
const gdv_697184f9ac3cfprevSlideButton = document.getElementById("gdv_697184f9ac3cfprevSlide"); const gdv_697184f9ac3cfnextSlideButton = document.getElementById("gdv_697184f9ac3cfnextSlide"); const gdv_697184f9ac3cfslideNumberDisplay = document.getElementById("gdv_697184f9ac3cfslideNumber"); const gdv_697184f9ac3cfimageName = document.getElementById("gdv_697184f9ac3cfimageName");
let gdv_697184f9ac3cfcurrentSlideIndex = 0;
gdv_697184f9ac3cfbrightnessInput.addEventListener("input", gdv_697184f9ac3cfdrawImage); gdv_697184f9ac3cfcontrastInput.addEventListener("input", gdv_697184f9ac3cfdrawImage);
const gdv_697184f9ac3cfimageUrls = [{"url":"https:\/\/drive.google.com\/thumbnail?id=1flFveOojs-SVeTYb9rzhfJVN-b8jqP0l&sz=w3000","name":"EPOL_Sur les biens des e\u0301migre\u0301s_nov 1792.jpg"}];
let gdv_697184f9ac3cfscale = 1; let gdv_697184f9ac3cforiginX = 0; let gdv_697184f9ac3cforiginY = 0; const gdv_697184f9ac3cfminScale = 0.1; const gdv_697184f9ac3cfmaxScale = 5; let gdv_697184f9ac3cfcurrentImage = new Image();
let gdv_697184f9ac3cfrotationAngle = 0;
gdv_697184f9ac3cfrotateRightButton.addEventListener("click", function() { gdv_697184f9ac3cfrotationAngle = (gdv_697184f9ac3cfrotationAngle + 90) % 360; gdv_697184f9ac3cfdrawImage(); });
gdv_697184f9ac3cfrotateLeftButton.addEventListener("click", function() { gdv_697184f9ac3cfrotationAngle = (gdv_697184f9ac3cfrotationAngle - 90 + 360) % 360; gdv_697184f9ac3cfdrawImage(); });
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_697184f9ac3cfcurrentImage.src = gdv_697184f9ac3cfimageUrls[0]["url"]; gdv_697184f9ac3cfimageName.innerHTML = filtrerChaine(gdv_697184f9ac3cfimageUrls[0]["name"], "rien"); gdv_697184f9ac3cfcurrentImage.onload = function() {
gdv_697184f9ac3cfupdateSlideNumber(); gdv_697184f9ac3cfresizeCanvas(); gdv_697184f9ac3cfdrawImage(); document.getElementById("gdv_697184f9ac3cfcontrols").style.display = "block"; };
function gdv_697184f9ac3cfupdateSlideNumber() { gdv_697184f9ac3cfslideNumberDisplay.textContent = `${gdv_697184f9ac3cfcurrentSlideIndex + 1} / ${gdv_697184f9ac3cfimageUrls.length}`; }
gdv_697184f9ac3cfprevSlideButton.addEventListener("click", function() { if (gdv_697184f9ac3cfcurrentSlideIndex > 0) { gdv_697184f9ac3cfcurrentSlideIndex--; gdv_697184f9ac3cfloadImage(gdv_697184f9ac3cfcurrentSlideIndex); gdv_697184f9ac3cfupdateSlideNumber(); } });
gdv_697184f9ac3cfnextSlideButton.addEventListener("click", function() { if (gdv_697184f9ac3cfcurrentSlideIndex < gdv_697184f9ac3cfimageUrls.length - 1) { gdv_697184f9ac3cfcurrentSlideIndex++; gdv_697184f9ac3cfloadImage(gdv_697184f9ac3cfcurrentSlideIndex); gdv_697184f9ac3cfupdateSlideNumber(); } }); function gdv_697184f9ac3cfresizeCanvas() { // Ajuster la taille du canvas pour correspondre à celle du conteneur const container = document.getElementById("gdv_697184f9ac3cfcanvasContainer"); gdv_697184f9ac3cfcanvas.width = container.clientWidth; gdv_697184f9ac3cfcanvas.height = container.clientHeight - 30; gdv_697184f9ac3cffitImageToCanvas(); // Redessiner le contenu du canvas ici gdv_697184f9ac3cfdrawImage(); } window.addEventListener("load", gdv_697184f9ac3cfresizeCanvas); window.addEventListener("resize", gdv_697184f9ac3cfresizeCanvas); function gdv_697184f9ac3cffitImageToCanvas() { const canvasAspect = gdv_697184f9ac3cfcanvas.width / gdv_697184f9ac3cfcanvas.height; const imageAspect = gdv_697184f9ac3cfcurrentImage.width / gdv_697184f9ac3cfcurrentImage.height; if (imageAspect > canvasAspect) { gdv_697184f9ac3cfscale = gdv_697184f9ac3cfcanvas.width / gdv_697184f9ac3cfcurrentImage.width; } else { gdv_697184f9ac3cfscale = gdv_697184f9ac3cfcanvas.height / gdv_697184f9ac3cfcurrentImage.height; } gdv_697184f9ac3cforiginX = gdv_697184f9ac3cfcanvas.width / 2; gdv_697184f9ac3cforiginY = gdv_697184f9ac3cfcanvas.height / 2; }
function gdv_697184f9ac3cfdrawImage() { gdv_697184f9ac3cfctx.clearRect(0, 0, gdv_697184f9ac3cfcanvas.width, gdv_697184f9ac3cfcanvas.height); gdv_697184f9ac3cfctx.save(); gdv_697184f9ac3cfctx.translate(gdv_697184f9ac3cforiginX, gdv_697184f9ac3cforiginY); gdv_697184f9ac3cfctx.rotate((Math.PI / 180) * gdv_697184f9ac3cfrotationAngle); gdv_697184f9ac3cfctx.scale(gdv_697184f9ac3cfscale, gdv_697184f9ac3cfscale);
// Appliquer la luminosité et le contraste gdv_697184f9ac3cfctx.filter = `brightness(${gdv_697184f9ac3cfbrightnessInput.value}) contrast(${gdv_697184f9ac3cfcontrastInput.value})`; gdv_697184f9ac3cfctx.drawImage(gdv_697184f9ac3cfcurrentImage, -gdv_697184f9ac3cfcurrentImage.width/2, -gdv_697184f9ac3cfcurrentImage.height/2); gdv_697184f9ac3cfctx.restore(); }
// Ajouter les miniatures des images gdv_697184f9ac3cfimageUrls.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_697184f9ac3cfloadImage(index); gdv_697184f9ac3cfcurrentSlideIndex = index; gdv_697184f9ac3cfupdateSlideNumber(); }; slide.appendChild(img); gdv_697184f9ac3cfthumbnailContainerWrapper.appendChild(slide); });
// Charger une image dans le canvas function gdv_697184f9ac3cfloadImage(index) { gdv_697184f9ac3cfcurrentImage.src = gdv_697184f9ac3cfimageUrls[index]["url"]; gdv_697184f9ac3cfimageName.innerHTML = filtrerChaine(gdv_697184f9ac3cfimageUrls[index]["name"], "rien"); gdv_697184f9ac3cfcurrentImage.onload = function() { gdv_697184f9ac3cfscale = 1; gdv_697184f9ac3cforiginX = 0; gdv_697184f9ac3cforiginY = 0; gdv_697184f9ac3cffitImageToCanvas(); gdv_697184f9ac3cfdrawImage(); };
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_697184f9ac3cfswiper = new Swiper(".gdv_697184f9ac3cfswiper-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_697184f9ac3cfswiper.on("slideChange", function () { // gdv_697184f9ac3cfcurrentSlideIndex = gdv_697184f9ac3cfswiper.activeIndex; // gdv_697184f9ac3cfupdateSlideNumber(); //});
// Plein écran gdv_697184f9ac3cffullscreenButton.addEventListener("click", function() { if (!document.fullscreenElement) { document.getElementById("gdv_697184f9ac3cfgd-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_697184f9ac3cfcanvas.addEventListener("wheel", function(event) { event.preventDefault(); const zoomFactor = 0.025; const mouseX = event.offsetX; const mouseY = event.offsetY;
let newScale = gdv_697184f9ac3cfscale; if (event.deltaY < 0) { newScale *= 1 + zoomFactor; } else { newScale /= 1 + zoomFactor; } newScale = Math.max(gdv_697184f9ac3cfminScale, Math.min(gdv_697184f9ac3cfmaxScale, newScale)); const scaleRatio = newScale / gdv_697184f9ac3cfscale; gdv_697184f9ac3cforiginX = mouseX - (mouseX - gdv_697184f9ac3cforiginX) * scaleRatio; gdv_697184f9ac3cforiginY = mouseY - (mouseY - gdv_697184f9ac3cforiginY) * scaleRatio; gdv_697184f9ac3cfscale = newScale; gdv_697184f9ac3cfdrawImage(); }); // Gestion du déplacement (pan) let gdv_697184f9ac3cfisDragging = false; let gdv_697184f9ac3cfstartX, gdv_697184f9ac3cfstartY; gdv_697184f9ac3cfcanvas.addEventListener("mousedown", function(event) { gdv_697184f9ac3cfisDragging = true; gdv_697184f9ac3cfstartX = event.offsetX - gdv_697184f9ac3cforiginX; gdv_697184f9ac3cfstartY = event.offsetY - gdv_697184f9ac3cforiginY; gdv_697184f9ac3cfcanvas.style.cursor = "grabbing"; }); gdv_697184f9ac3cfcanvas.addEventListener("mousemove", function(event) { if (gdv_697184f9ac3cfisDragging) { gdv_697184f9ac3cforiginX = event.offsetX - gdv_697184f9ac3cfstartX; gdv_697184f9ac3cforiginY = event.offsetY - gdv_697184f9ac3cfstartY; gdv_697184f9ac3cfdrawImage(); } }); // Gestion des événements tactiles gdv_697184f9ac3cfcanvas.addEventListener("touchstart", function(event) { if (event.touches.length === 1) { gdv_697184f9ac3cfisDragging = true; const touch = event.touches[0]; gdv_697184f9ac3cfstartX = touch.pageX - gdv_697184f9ac3cforiginX; gdv_697184f9ac3cfstartY = touch.pageY - gdv_697184f9ac3cforiginY; } }); gdv_697184f9ac3cfcanvas.addEventListener("touchmove", function(event) { event.preventDefault(); // Empêche le comportement par défaut du navigateur const touch = event.touches[0]; gdv_697184f9ac3cforiginX = touch.pageX - gdv_697184f9ac3cfstartX; gdv_697184f9ac3cforiginY = touch.pageY - gdv_697184f9ac3cfstartY; gdv_697184f9ac3cfdrawImage(); }); gdv_697184f9ac3cfcanvas.addEventListener("touchend", function() { gdv_697184f9ac3cfisDragging = false; }); gdv_697184f9ac3cfcanvas.addEventListener("mouseup", function() { gdv_697184f9ac3cfisDragging = false; gdv_697184f9ac3cfcanvas.style.cursor = "grab"; }); gdv_697184f9ac3cfcanvas.addEventListener("mouseleave", function() { gdv_697184f9ac3cfisDragging = false; gdv_697184f9ac3cfcanvas.style.cursor = "grab"; }); gdv_697184f9ac3cfzoomInButton.addEventListener("click", function() { let newScale = gdv_697184f9ac3cfscale; const zoomFactor = 0.025; newScale *= 1 + zoomFactor; gdv_697184f9ac3cfscale = Math.max(gdv_697184f9ac3cfminScale, Math.min(gdv_697184f9ac3cfmaxScale, newScale)); gdv_697184f9ac3cfdrawImage(); }); gdv_697184f9ac3cfzoomOutButton.addEventListener("click", function() { let newScale = gdv_697184f9ac3cfscale; const zoomFactor = 0.025; newScale /= 1 + zoomFactor; gdv_697184f9ac3cfscale = Math.max(gdv_697184f9ac3cfminScale, Math.min(gdv_697184f9ac3cfmaxScale, newScale)); gdv_697184f9ac3cfdrawImage(); }); gdv_697184f9ac3cfresetZoomButton.addEventListener("click", function() { gdv_697184f9ac3cfrotationAngle = 0; gdv_697184f9ac3cffitImageToCanvas(); gdv_697184f9ac3cfdrawImage(); }); function gdv_697184f9ac3cfgetImageIdFromUrl(url) { const urlObj = new URL(url); return urlObj.searchParams.get("id"); } document.getElementById("gdv_697184f9ac3cfdownloadImage").addEventListener("click", function() { let url = gdv_697184f9ac3cfcurrentImage.src; const imageId = gdv_697184f9ac3cfgetImageIdFromUrl(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_697184f9ac3cfprintImageFromApi(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_697184f9ac3cfprintButton = document.getElementById("gdv_697184f9ac3cfprintCanvas");
gdv_697184f9ac3cfprintButton.addEventListener("click", function() { let url = gdv_697184f9ac3cfcurrentImage.src; const imageId = gdv_697184f9ac3cfgetImageIdFromUrl(url); gdv_697184f9ac3cfprintImageFromApi(imageId); });
let gdv_697184f9ac3cfinitialDistance = 0; let gdv_697184f9ac3cfinitialScale = 1;
gdv_697184f9ac3cfcanvas.addEventListener("touchstart", function(event) { if (event.touches.length === 2) { event.preventDefault(); gdv_697184f9ac3cfinitialDistance = getDistance(event.touches[0], event.touches[1]); gdv_697184f9ac3cfinitialScale = gdv_697184f9ac3cfscale; } });
gdv_697184f9ac3cfcanvas.addEventListener("touchmove", function(event) { if (event.touches.length === 2) { event.preventDefault(); const currentDistance = getDistance(event.touches[0], event.touches[1]); const scaleChange = currentDistance / gdv_697184f9ac3cfinitialDistance; let newScale = gdv_697184f9ac3cfinitialScale * scaleChange;
newScale = Math.max(gdv_697184f9ac3cfminScale, Math.min(gdv_697184f9ac3cfmaxScale, 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_697184f9ac3cfscale; gdv_697184f9ac3cforiginX = centerX - (centerX - gdv_697184f9ac3cforiginX) * scaleRatio; gdv_697184f9ac3cforiginY = centerY - (centerY - gdv_697184f9ac3cforiginY) * scaleRatio;
gdv_697184f9ac3cfscale = newScale; gdv_697184f9ac3cfdrawImage(); // 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); }