1 / X
const gdv_6ad406d9a74bacanvas = document.getElementById("gdv_6ad406d9a74baimageCanvas"); const gdv_6ad406d9a74bactx = gdv_6ad406d9a74bacanvas.getContext("2d");
const gdv_6ad406d9a74bathumbnailContainer = document.getElementById("gdv_6ad406d9a74bathumbnailContainer"); const gdv_6ad406d9a74bathumbnailContainerWrapper = document.getElementById("gdv_6ad406d9a74bathumbnailContainerWrapper"); const gdv_6ad406d9a74bazoomInButton = document.getElementById("gdv_6ad406d9a74bazoomIn"); const gdv_6ad406d9a74bazoomOutButton = document.getElementById("gdv_6ad406d9a74bazoomOut"); const gdv_6ad406d9a74baresetZoomButton = document.getElementById("gdv_6ad406d9a74baresetZoom");
const gdv_6ad406d9a74babrightnessInput = document.getElementById("gdv_6ad406d9a74babrightness"); const gdv_6ad406d9a74bacontrastInput = document.getElementById("gdv_6ad406d9a74bacontrast"); const gdv_6ad406d9a74bafullscreenButton = document.getElementById("gdv_6ad406d9a74bafullscreen");
const gdv_6ad406d9a74barotateRightButton = document.getElementById("gdv_6ad406d9a74barotateRight"); const gdv_6ad406d9a74barotateLeftButton = document.getElementById("gdv_6ad406d9a74barotateLeft");
const gdv_6ad406d9a74baprevSlideButton = document.getElementById("gdv_6ad406d9a74baprevSlide"); const gdv_6ad406d9a74banextSlideButton = document.getElementById("gdv_6ad406d9a74banextSlide"); const gdv_6ad406d9a74baslideNumberDisplay = document.getElementById("gdv_6ad406d9a74baslideNumber"); const gdv_6ad406d9a74baimageName = document.getElementById("gdv_6ad406d9a74baimageName");
let gdv_6ad406d9a74bacurrentSlideIndex = 0;
gdv_6ad406d9a74babrightnessInput.addEventListener("input", gdv_6ad406d9a74badrawImage); gdv_6ad406d9a74bacontrastInput.addEventListener("input", gdv_6ad406d9a74badrawImage);
const gdv_6ad406d9a74baimageUrls = [{"url":"https:\/\/drive.google.com\/thumbnail?id=1fHqdAXMWLC5TFWxmVdPPgQcze8PJcxo9&sz=w3000","name":"EPOL_LFS_interdiction de s'approprier les me\u0301taux des ruines du Cap.jpg"}];
let gdv_6ad406d9a74bascale = 1; let gdv_6ad406d9a74baoriginX = 0; let gdv_6ad406d9a74baoriginY = 0; const gdv_6ad406d9a74baminScale = 0.1; const gdv_6ad406d9a74bamaxScale = 5; let gdv_6ad406d9a74bacurrentImage = new Image();
let gdv_6ad406d9a74barotationAngle = 0;
gdv_6ad406d9a74barotateRightButton.addEventListener("click", function() { gdv_6ad406d9a74barotationAngle = (gdv_6ad406d9a74barotationAngle + 90) % 360; gdv_6ad406d9a74badrawImage(); });
gdv_6ad406d9a74barotateLeftButton.addEventListener("click", function() { gdv_6ad406d9a74barotationAngle = (gdv_6ad406d9a74barotationAngle - 90 + 360) % 360; gdv_6ad406d9a74badrawImage(); });
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_6ad406d9a74bacurrentImage.src = gdv_6ad406d9a74baimageUrls[0]["url"]; gdv_6ad406d9a74baimageName.innerHTML = filtrerChaine(gdv_6ad406d9a74baimageUrls[0]["name"], "rien"); gdv_6ad406d9a74bacurrentImage.onload = function() {
gdv_6ad406d9a74baupdateSlideNumber(); gdv_6ad406d9a74baresizeCanvas(); gdv_6ad406d9a74badrawImage(); document.getElementById("gdv_6ad406d9a74bacontrols").style.display = "block"; };
function gdv_6ad406d9a74baupdateSlideNumber() { gdv_6ad406d9a74baslideNumberDisplay.textContent = `${gdv_6ad406d9a74bacurrentSlideIndex + 1} / ${gdv_6ad406d9a74baimageUrls.length}`; }
gdv_6ad406d9a74baprevSlideButton.addEventListener("click", function() { if (gdv_6ad406d9a74bacurrentSlideIndex > 0) { gdv_6ad406d9a74bacurrentSlideIndex--; gdv_6ad406d9a74baloadImage(gdv_6ad406d9a74bacurrentSlideIndex); gdv_6ad406d9a74baupdateSlideNumber(); } });
gdv_6ad406d9a74banextSlideButton.addEventListener("click", function() { if (gdv_6ad406d9a74bacurrentSlideIndex < gdv_6ad406d9a74baimageUrls.length - 1) { gdv_6ad406d9a74bacurrentSlideIndex++; gdv_6ad406d9a74baloadImage(gdv_6ad406d9a74bacurrentSlideIndex); gdv_6ad406d9a74baupdateSlideNumber(); } }); function gdv_6ad406d9a74baresizeCanvas() { // Ajuster la taille du canvas pour correspondre à celle du conteneur const container = document.getElementById("gdv_6ad406d9a74bacanvasContainer"); gdv_6ad406d9a74bacanvas.width = container.clientWidth; gdv_6ad406d9a74bacanvas.height = container.clientHeight - 30; gdv_6ad406d9a74bafitImageToCanvas(); // Redessiner le contenu du canvas ici gdv_6ad406d9a74badrawImage(); } window.addEventListener("load", gdv_6ad406d9a74baresizeCanvas); window.addEventListener("resize", gdv_6ad406d9a74baresizeCanvas); function gdv_6ad406d9a74bafitImageToCanvas() { const canvasAspect = gdv_6ad406d9a74bacanvas.width / gdv_6ad406d9a74bacanvas.height; const imageAspect = gdv_6ad406d9a74bacurrentImage.width / gdv_6ad406d9a74bacurrentImage.height; if (imageAspect > canvasAspect) { gdv_6ad406d9a74bascale = gdv_6ad406d9a74bacanvas.width / gdv_6ad406d9a74bacurrentImage.width; } else { gdv_6ad406d9a74bascale = gdv_6ad406d9a74bacanvas.height / gdv_6ad406d9a74bacurrentImage.height; } gdv_6ad406d9a74baoriginX = gdv_6ad406d9a74bacanvas.width / 2; gdv_6ad406d9a74baoriginY = gdv_6ad406d9a74bacanvas.height / 2; }
function gdv_6ad406d9a74badrawImage() { gdv_6ad406d9a74bactx.clearRect(0, 0, gdv_6ad406d9a74bacanvas.width, gdv_6ad406d9a74bacanvas.height); gdv_6ad406d9a74bactx.save(); gdv_6ad406d9a74bactx.translate(gdv_6ad406d9a74baoriginX, gdv_6ad406d9a74baoriginY); gdv_6ad406d9a74bactx.rotate((Math.PI / 180) * gdv_6ad406d9a74barotationAngle); gdv_6ad406d9a74bactx.scale(gdv_6ad406d9a74bascale, gdv_6ad406d9a74bascale);
// Appliquer la luminosité et le contraste gdv_6ad406d9a74bactx.filter = `brightness(${gdv_6ad406d9a74babrightnessInput.value}) contrast(${gdv_6ad406d9a74bacontrastInput.value})`; gdv_6ad406d9a74bactx.drawImage(gdv_6ad406d9a74bacurrentImage, -gdv_6ad406d9a74bacurrentImage.width/2, -gdv_6ad406d9a74bacurrentImage.height/2); gdv_6ad406d9a74bactx.restore(); }
// Ajouter les miniatures des images gdv_6ad406d9a74baimageUrls.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_6ad406d9a74baloadImage(index); gdv_6ad406d9a74bacurrentSlideIndex = index; gdv_6ad406d9a74baupdateSlideNumber(); }; slide.appendChild(img); gdv_6ad406d9a74bathumbnailContainerWrapper.appendChild(slide); });
// Charger une image dans le canvas function gdv_6ad406d9a74baloadImage(index) { gdv_6ad406d9a74bacurrentImage.src = gdv_6ad406d9a74baimageUrls[index]["url"]; gdv_6ad406d9a74baimageName.innerHTML = filtrerChaine(gdv_6ad406d9a74baimageUrls[index]["name"], "rien"); gdv_6ad406d9a74bacurrentImage.onload = function() { gdv_6ad406d9a74bascale = 1; gdv_6ad406d9a74baoriginX = 0; gdv_6ad406d9a74baoriginY = 0; gdv_6ad406d9a74bafitImageToCanvas(); gdv_6ad406d9a74badrawImage(); };
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_6ad406d9a74baswiper = new Swiper(".gdv_6ad406d9a74baswiper-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_6ad406d9a74baswiper.on("slideChange", function () { // gdv_6ad406d9a74bacurrentSlideIndex = gdv_6ad406d9a74baswiper.activeIndex; // gdv_6ad406d9a74baupdateSlideNumber(); //});
// Plein écran gdv_6ad406d9a74bafullscreenButton.addEventListener("click", function() { if (!document.fullscreenElement) { document.getElementById("gdv_6ad406d9a74bagd-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_6ad406d9a74bacanvas.addEventListener("wheel", function(event) { event.preventDefault(); const zoomFactor = 0.025; const mouseX = event.offsetX; const mouseY = event.offsetY;
let newScale = gdv_6ad406d9a74bascale; if (event.deltaY < 0) { newScale *= 1 + zoomFactor; } else { newScale /= 1 + zoomFactor; } newScale = Math.max(gdv_6ad406d9a74baminScale, Math.min(gdv_6ad406d9a74bamaxScale, newScale)); const scaleRatio = newScale / gdv_6ad406d9a74bascale; gdv_6ad406d9a74baoriginX = mouseX - (mouseX - gdv_6ad406d9a74baoriginX) * scaleRatio; gdv_6ad406d9a74baoriginY = mouseY - (mouseY - gdv_6ad406d9a74baoriginY) * scaleRatio; gdv_6ad406d9a74bascale = newScale; gdv_6ad406d9a74badrawImage(); }); // Gestion du déplacement (pan) let gdv_6ad406d9a74baisDragging = false; let gdv_6ad406d9a74bastartX, gdv_6ad406d9a74bastartY; gdv_6ad406d9a74bacanvas.addEventListener("mousedown", function(event) { gdv_6ad406d9a74baisDragging = true; gdv_6ad406d9a74bastartX = event.offsetX - gdv_6ad406d9a74baoriginX; gdv_6ad406d9a74bastartY = event.offsetY - gdv_6ad406d9a74baoriginY; gdv_6ad406d9a74bacanvas.style.cursor = "grabbing"; }); gdv_6ad406d9a74bacanvas.addEventListener("mousemove", function(event) { if (gdv_6ad406d9a74baisDragging) { gdv_6ad406d9a74baoriginX = event.offsetX - gdv_6ad406d9a74bastartX; gdv_6ad406d9a74baoriginY = event.offsetY - gdv_6ad406d9a74bastartY; gdv_6ad406d9a74badrawImage(); } }); // Gestion des événements tactiles gdv_6ad406d9a74bacanvas.addEventListener("touchstart", function(event) { if (event.touches.length === 1) { gdv_6ad406d9a74baisDragging = true; const touch = event.touches[0]; gdv_6ad406d9a74bastartX = touch.pageX - gdv_6ad406d9a74baoriginX; gdv_6ad406d9a74bastartY = touch.pageY - gdv_6ad406d9a74baoriginY; } }); gdv_6ad406d9a74bacanvas.addEventListener("touchmove", function(event) { event.preventDefault(); // Empêche le comportement par défaut du navigateur const touch = event.touches[0]; gdv_6ad406d9a74baoriginX = touch.pageX - gdv_6ad406d9a74bastartX; gdv_6ad406d9a74baoriginY = touch.pageY - gdv_6ad406d9a74bastartY; gdv_6ad406d9a74badrawImage(); }); gdv_6ad406d9a74bacanvas.addEventListener("touchend", function() { gdv_6ad406d9a74baisDragging = false; }); gdv_6ad406d9a74bacanvas.addEventListener("mouseup", function() { gdv_6ad406d9a74baisDragging = false; gdv_6ad406d9a74bacanvas.style.cursor = "grab"; }); gdv_6ad406d9a74bacanvas.addEventListener("mouseleave", function() { gdv_6ad406d9a74baisDragging = false; gdv_6ad406d9a74bacanvas.style.cursor = "grab"; }); gdv_6ad406d9a74bazoomInButton.addEventListener("click", function() { let newScale = gdv_6ad406d9a74bascale; const zoomFactor = 0.025; newScale *= 1 + zoomFactor; gdv_6ad406d9a74bascale = Math.max(gdv_6ad406d9a74baminScale, Math.min(gdv_6ad406d9a74bamaxScale, newScale)); gdv_6ad406d9a74badrawImage(); }); gdv_6ad406d9a74bazoomOutButton.addEventListener("click", function() { let newScale = gdv_6ad406d9a74bascale; const zoomFactor = 0.025; newScale /= 1 + zoomFactor; gdv_6ad406d9a74bascale = Math.max(gdv_6ad406d9a74baminScale, Math.min(gdv_6ad406d9a74bamaxScale, newScale)); gdv_6ad406d9a74badrawImage(); }); gdv_6ad406d9a74baresetZoomButton.addEventListener("click", function() { gdv_6ad406d9a74barotationAngle = 0; gdv_6ad406d9a74bafitImageToCanvas(); gdv_6ad406d9a74badrawImage(); }); function gdv_6ad406d9a74bagetImageIdFromUrl(url) { const urlObj = new URL(url); return urlObj.searchParams.get("id"); } document.getElementById("gdv_6ad406d9a74badownloadImage").addEventListener("click", function() { let url = gdv_6ad406d9a74bacurrentImage.src; const imageId = gdv_6ad406d9a74bagetImageIdFromUrl(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_6ad406d9a74baprintImageFromApi(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_6ad406d9a74baprintButton = document.getElementById("gdv_6ad406d9a74baprintCanvas");
gdv_6ad406d9a74baprintButton.addEventListener("click", function() { let url = gdv_6ad406d9a74bacurrentImage.src; const imageId = gdv_6ad406d9a74bagetImageIdFromUrl(url); gdv_6ad406d9a74baprintImageFromApi(imageId); });
let gdv_6ad406d9a74bainitialDistance = 0; let gdv_6ad406d9a74bainitialScale = 1;
gdv_6ad406d9a74bacanvas.addEventListener("touchstart", function(event) { if (event.touches.length === 2) { event.preventDefault(); gdv_6ad406d9a74bainitialDistance = getDistance(event.touches[0], event.touches[1]); gdv_6ad406d9a74bainitialScale = gdv_6ad406d9a74bascale; } });
gdv_6ad406d9a74bacanvas.addEventListener("touchmove", function(event) { if (event.touches.length === 2) { event.preventDefault(); const currentDistance = getDistance(event.touches[0], event.touches[1]); const scaleChange = currentDistance / gdv_6ad406d9a74bainitialDistance; let newScale = gdv_6ad406d9a74bainitialScale * scaleChange;
newScale = Math.max(gdv_6ad406d9a74baminScale, Math.min(gdv_6ad406d9a74bamaxScale, 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_6ad406d9a74bascale; gdv_6ad406d9a74baoriginX = centerX - (centerX - gdv_6ad406d9a74baoriginX) * scaleRatio; gdv_6ad406d9a74baoriginY = centerY - (centerY - gdv_6ad406d9a74baoriginY) * scaleRatio;
gdv_6ad406d9a74bascale = newScale; gdv_6ad406d9a74badrawImage(); // 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); }