1 / X
const gdv_69a1f286cafd6canvas = document.getElementById("gdv_69a1f286cafd6imageCanvas"); const gdv_69a1f286cafd6ctx = gdv_69a1f286cafd6canvas.getContext("2d");
const gdv_69a1f286cafd6thumbnailContainer = document.getElementById("gdv_69a1f286cafd6thumbnailContainer"); const gdv_69a1f286cafd6thumbnailContainerWrapper = document.getElementById("gdv_69a1f286cafd6thumbnailContainerWrapper"); const gdv_69a1f286cafd6zoomInButton = document.getElementById("gdv_69a1f286cafd6zoomIn"); const gdv_69a1f286cafd6zoomOutButton = document.getElementById("gdv_69a1f286cafd6zoomOut"); const gdv_69a1f286cafd6resetZoomButton = document.getElementById("gdv_69a1f286cafd6resetZoom");
const gdv_69a1f286cafd6brightnessInput = document.getElementById("gdv_69a1f286cafd6brightness"); const gdv_69a1f286cafd6contrastInput = document.getElementById("gdv_69a1f286cafd6contrast"); const gdv_69a1f286cafd6fullscreenButton = document.getElementById("gdv_69a1f286cafd6fullscreen");
const gdv_69a1f286cafd6rotateRightButton = document.getElementById("gdv_69a1f286cafd6rotateRight"); const gdv_69a1f286cafd6rotateLeftButton = document.getElementById("gdv_69a1f286cafd6rotateLeft");
const gdv_69a1f286cafd6prevSlideButton = document.getElementById("gdv_69a1f286cafd6prevSlide"); const gdv_69a1f286cafd6nextSlideButton = document.getElementById("gdv_69a1f286cafd6nextSlide"); const gdv_69a1f286cafd6slideNumberDisplay = document.getElementById("gdv_69a1f286cafd6slideNumber"); const gdv_69a1f286cafd6imageName = document.getElementById("gdv_69a1f286cafd6imageName");
let gdv_69a1f286cafd6currentSlideIndex = 0;
gdv_69a1f286cafd6brightnessInput.addEventListener("input", gdv_69a1f286cafd6drawImage); gdv_69a1f286cafd6contrastInput.addEventListener("input", gdv_69a1f286cafd6drawImage);
const gdv_69a1f286cafd6imageUrls = [{"url":"https:\/\/drive.google.com\/thumbnail?id=1TfoGnl1dK0DMYAw44K87vq4Ys3pGzRPP&sz=w3000","name":"EPOL et LFS_ Interdiction de la Croix de Saint-Louis.jpg"}];
let gdv_69a1f286cafd6scale = 1; let gdv_69a1f286cafd6originX = 0; let gdv_69a1f286cafd6originY = 0; const gdv_69a1f286cafd6minScale = 0.1; const gdv_69a1f286cafd6maxScale = 5; let gdv_69a1f286cafd6currentImage = new Image();
let gdv_69a1f286cafd6rotationAngle = 0;
gdv_69a1f286cafd6rotateRightButton.addEventListener("click", function() { gdv_69a1f286cafd6rotationAngle = (gdv_69a1f286cafd6rotationAngle + 90) % 360; gdv_69a1f286cafd6drawImage(); });
gdv_69a1f286cafd6rotateLeftButton.addEventListener("click", function() { gdv_69a1f286cafd6rotationAngle = (gdv_69a1f286cafd6rotationAngle - 90 + 360) % 360; gdv_69a1f286cafd6drawImage(); });
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_69a1f286cafd6currentImage.src = gdv_69a1f286cafd6imageUrls[0]["url"]; gdv_69a1f286cafd6imageName.innerHTML = filtrerChaine(gdv_69a1f286cafd6imageUrls[0]["name"], "rien"); gdv_69a1f286cafd6currentImage.onload = function() {
gdv_69a1f286cafd6updateSlideNumber(); gdv_69a1f286cafd6resizeCanvas(); gdv_69a1f286cafd6drawImage(); document.getElementById("gdv_69a1f286cafd6controls").style.display = "block"; };
function gdv_69a1f286cafd6updateSlideNumber() { gdv_69a1f286cafd6slideNumberDisplay.textContent = `${gdv_69a1f286cafd6currentSlideIndex + 1} / ${gdv_69a1f286cafd6imageUrls.length}`; }
gdv_69a1f286cafd6prevSlideButton.addEventListener("click", function() { if (gdv_69a1f286cafd6currentSlideIndex > 0) { gdv_69a1f286cafd6currentSlideIndex--; gdv_69a1f286cafd6loadImage(gdv_69a1f286cafd6currentSlideIndex); gdv_69a1f286cafd6updateSlideNumber(); } });
gdv_69a1f286cafd6nextSlideButton.addEventListener("click", function() { if (gdv_69a1f286cafd6currentSlideIndex < gdv_69a1f286cafd6imageUrls.length - 1) { gdv_69a1f286cafd6currentSlideIndex++; gdv_69a1f286cafd6loadImage(gdv_69a1f286cafd6currentSlideIndex); gdv_69a1f286cafd6updateSlideNumber(); } }); function gdv_69a1f286cafd6resizeCanvas() { // Ajuster la taille du canvas pour correspondre à celle du conteneur const container = document.getElementById("gdv_69a1f286cafd6canvasContainer"); gdv_69a1f286cafd6canvas.width = container.clientWidth; gdv_69a1f286cafd6canvas.height = container.clientHeight - 30; gdv_69a1f286cafd6fitImageToCanvas(); // Redessiner le contenu du canvas ici gdv_69a1f286cafd6drawImage(); } window.addEventListener("load", gdv_69a1f286cafd6resizeCanvas); window.addEventListener("resize", gdv_69a1f286cafd6resizeCanvas); function gdv_69a1f286cafd6fitImageToCanvas() { const canvasAspect = gdv_69a1f286cafd6canvas.width / gdv_69a1f286cafd6canvas.height; const imageAspect = gdv_69a1f286cafd6currentImage.width / gdv_69a1f286cafd6currentImage.height; if (imageAspect > canvasAspect) { gdv_69a1f286cafd6scale = gdv_69a1f286cafd6canvas.width / gdv_69a1f286cafd6currentImage.width; } else { gdv_69a1f286cafd6scale = gdv_69a1f286cafd6canvas.height / gdv_69a1f286cafd6currentImage.height; } gdv_69a1f286cafd6originX = gdv_69a1f286cafd6canvas.width / 2; gdv_69a1f286cafd6originY = gdv_69a1f286cafd6canvas.height / 2; }
function gdv_69a1f286cafd6drawImage() { gdv_69a1f286cafd6ctx.clearRect(0, 0, gdv_69a1f286cafd6canvas.width, gdv_69a1f286cafd6canvas.height); gdv_69a1f286cafd6ctx.save(); gdv_69a1f286cafd6ctx.translate(gdv_69a1f286cafd6originX, gdv_69a1f286cafd6originY); gdv_69a1f286cafd6ctx.rotate((Math.PI / 180) * gdv_69a1f286cafd6rotationAngle); gdv_69a1f286cafd6ctx.scale(gdv_69a1f286cafd6scale, gdv_69a1f286cafd6scale);
// Appliquer la luminosité et le contraste gdv_69a1f286cafd6ctx.filter = `brightness(${gdv_69a1f286cafd6brightnessInput.value}) contrast(${gdv_69a1f286cafd6contrastInput.value})`; gdv_69a1f286cafd6ctx.drawImage(gdv_69a1f286cafd6currentImage, -gdv_69a1f286cafd6currentImage.width/2, -gdv_69a1f286cafd6currentImage.height/2); gdv_69a1f286cafd6ctx.restore(); }
// Ajouter les miniatures des images gdv_69a1f286cafd6imageUrls.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_69a1f286cafd6loadImage(index); gdv_69a1f286cafd6currentSlideIndex = index; gdv_69a1f286cafd6updateSlideNumber(); }; slide.appendChild(img); gdv_69a1f286cafd6thumbnailContainerWrapper.appendChild(slide); });
// Charger une image dans le canvas function gdv_69a1f286cafd6loadImage(index) { gdv_69a1f286cafd6currentImage.src = gdv_69a1f286cafd6imageUrls[index]["url"]; gdv_69a1f286cafd6imageName.innerHTML = filtrerChaine(gdv_69a1f286cafd6imageUrls[index]["name"], "rien"); gdv_69a1f286cafd6currentImage.onload = function() { gdv_69a1f286cafd6scale = 1; gdv_69a1f286cafd6originX = 0; gdv_69a1f286cafd6originY = 0; gdv_69a1f286cafd6fitImageToCanvas(); gdv_69a1f286cafd6drawImage(); };
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_69a1f286cafd6swiper = new Swiper(".gdv_69a1f286cafd6swiper-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_69a1f286cafd6swiper.on("slideChange", function () { // gdv_69a1f286cafd6currentSlideIndex = gdv_69a1f286cafd6swiper.activeIndex; // gdv_69a1f286cafd6updateSlideNumber(); //});
// Plein écran gdv_69a1f286cafd6fullscreenButton.addEventListener("click", function() { if (!document.fullscreenElement) { document.getElementById("gdv_69a1f286cafd6gd-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_69a1f286cafd6canvas.addEventListener("wheel", function(event) { event.preventDefault(); const zoomFactor = 0.025; const mouseX = event.offsetX; const mouseY = event.offsetY;
let newScale = gdv_69a1f286cafd6scale; if (event.deltaY < 0) { newScale *= 1 + zoomFactor; } else { newScale /= 1 + zoomFactor; } newScale = Math.max(gdv_69a1f286cafd6minScale, Math.min(gdv_69a1f286cafd6maxScale, newScale)); const scaleRatio = newScale / gdv_69a1f286cafd6scale; gdv_69a1f286cafd6originX = mouseX - (mouseX - gdv_69a1f286cafd6originX) * scaleRatio; gdv_69a1f286cafd6originY = mouseY - (mouseY - gdv_69a1f286cafd6originY) * scaleRatio; gdv_69a1f286cafd6scale = newScale; gdv_69a1f286cafd6drawImage(); }); // Gestion du déplacement (pan) let gdv_69a1f286cafd6isDragging = false; let gdv_69a1f286cafd6startX, gdv_69a1f286cafd6startY; gdv_69a1f286cafd6canvas.addEventListener("mousedown", function(event) { gdv_69a1f286cafd6isDragging = true; gdv_69a1f286cafd6startX = event.offsetX - gdv_69a1f286cafd6originX; gdv_69a1f286cafd6startY = event.offsetY - gdv_69a1f286cafd6originY; gdv_69a1f286cafd6canvas.style.cursor = "grabbing"; }); gdv_69a1f286cafd6canvas.addEventListener("mousemove", function(event) { if (gdv_69a1f286cafd6isDragging) { gdv_69a1f286cafd6originX = event.offsetX - gdv_69a1f286cafd6startX; gdv_69a1f286cafd6originY = event.offsetY - gdv_69a1f286cafd6startY; gdv_69a1f286cafd6drawImage(); } }); // Gestion des événements tactiles gdv_69a1f286cafd6canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 1) { gdv_69a1f286cafd6isDragging = true; const touch = event.touches[0]; gdv_69a1f286cafd6startX = touch.pageX - gdv_69a1f286cafd6originX; gdv_69a1f286cafd6startY = touch.pageY - gdv_69a1f286cafd6originY; } }); gdv_69a1f286cafd6canvas.addEventListener("touchmove", function(event) { event.preventDefault(); // Empêche le comportement par défaut du navigateur const touch = event.touches[0]; gdv_69a1f286cafd6originX = touch.pageX - gdv_69a1f286cafd6startX; gdv_69a1f286cafd6originY = touch.pageY - gdv_69a1f286cafd6startY; gdv_69a1f286cafd6drawImage(); }); gdv_69a1f286cafd6canvas.addEventListener("touchend", function() { gdv_69a1f286cafd6isDragging = false; }); gdv_69a1f286cafd6canvas.addEventListener("mouseup", function() { gdv_69a1f286cafd6isDragging = false; gdv_69a1f286cafd6canvas.style.cursor = "grab"; }); gdv_69a1f286cafd6canvas.addEventListener("mouseleave", function() { gdv_69a1f286cafd6isDragging = false; gdv_69a1f286cafd6canvas.style.cursor = "grab"; }); gdv_69a1f286cafd6zoomInButton.addEventListener("click", function() { let newScale = gdv_69a1f286cafd6scale; const zoomFactor = 0.025; newScale *= 1 + zoomFactor; gdv_69a1f286cafd6scale = Math.max(gdv_69a1f286cafd6minScale, Math.min(gdv_69a1f286cafd6maxScale, newScale)); gdv_69a1f286cafd6drawImage(); }); gdv_69a1f286cafd6zoomOutButton.addEventListener("click", function() { let newScale = gdv_69a1f286cafd6scale; const zoomFactor = 0.025; newScale /= 1 + zoomFactor; gdv_69a1f286cafd6scale = Math.max(gdv_69a1f286cafd6minScale, Math.min(gdv_69a1f286cafd6maxScale, newScale)); gdv_69a1f286cafd6drawImage(); }); gdv_69a1f286cafd6resetZoomButton.addEventListener("click", function() { gdv_69a1f286cafd6rotationAngle = 0; gdv_69a1f286cafd6fitImageToCanvas(); gdv_69a1f286cafd6drawImage(); }); function gdv_69a1f286cafd6getImageIdFromUrl(url) { const urlObj = new URL(url); return urlObj.searchParams.get("id"); } document.getElementById("gdv_69a1f286cafd6downloadImage").addEventListener("click", function() { let url = gdv_69a1f286cafd6currentImage.src; const imageId = gdv_69a1f286cafd6getImageIdFromUrl(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_69a1f286cafd6printImageFromApi(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_69a1f286cafd6printButton = document.getElementById("gdv_69a1f286cafd6printCanvas");
gdv_69a1f286cafd6printButton.addEventListener("click", function() { let url = gdv_69a1f286cafd6currentImage.src; const imageId = gdv_69a1f286cafd6getImageIdFromUrl(url); gdv_69a1f286cafd6printImageFromApi(imageId); });
let gdv_69a1f286cafd6initialDistance = 0; let gdv_69a1f286cafd6initialScale = 1;
gdv_69a1f286cafd6canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 2) { event.preventDefault(); gdv_69a1f286cafd6initialDistance = getDistance(event.touches[0], event.touches[1]); gdv_69a1f286cafd6initialScale = gdv_69a1f286cafd6scale; } });
gdv_69a1f286cafd6canvas.addEventListener("touchmove", function(event) { if (event.touches.length === 2) { event.preventDefault(); const currentDistance = getDistance(event.touches[0], event.touches[1]); const scaleChange = currentDistance / gdv_69a1f286cafd6initialDistance; let newScale = gdv_69a1f286cafd6initialScale * scaleChange;
newScale = Math.max(gdv_69a1f286cafd6minScale, Math.min(gdv_69a1f286cafd6maxScale, 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_69a1f286cafd6scale; gdv_69a1f286cafd6originX = centerX - (centerX - gdv_69a1f286cafd6originX) * scaleRatio; gdv_69a1f286cafd6originY = centerY - (centerY - gdv_69a1f286cafd6originY) * scaleRatio;
gdv_69a1f286cafd6scale = newScale; gdv_69a1f286cafd6drawImage(); // 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); }