1 / X
const gdv_69b5cc9769682canvas = document.getElementById("gdv_69b5cc9769682imageCanvas"); const gdv_69b5cc9769682ctx = gdv_69b5cc9769682canvas.getContext("2d");
const gdv_69b5cc9769682thumbnailContainer = document.getElementById("gdv_69b5cc9769682thumbnailContainer"); const gdv_69b5cc9769682thumbnailContainerWrapper = document.getElementById("gdv_69b5cc9769682thumbnailContainerWrapper"); const gdv_69b5cc9769682zoomInButton = document.getElementById("gdv_69b5cc9769682zoomIn"); const gdv_69b5cc9769682zoomOutButton = document.getElementById("gdv_69b5cc9769682zoomOut"); const gdv_69b5cc9769682resetZoomButton = document.getElementById("gdv_69b5cc9769682resetZoom");
const gdv_69b5cc9769682brightnessInput = document.getElementById("gdv_69b5cc9769682brightness"); const gdv_69b5cc9769682contrastInput = document.getElementById("gdv_69b5cc9769682contrast"); const gdv_69b5cc9769682fullscreenButton = document.getElementById("gdv_69b5cc9769682fullscreen");
const gdv_69b5cc9769682rotateRightButton = document.getElementById("gdv_69b5cc9769682rotateRight"); const gdv_69b5cc9769682rotateLeftButton = document.getElementById("gdv_69b5cc9769682rotateLeft");
const gdv_69b5cc9769682prevSlideButton = document.getElementById("gdv_69b5cc9769682prevSlide"); const gdv_69b5cc9769682nextSlideButton = document.getElementById("gdv_69b5cc9769682nextSlide"); const gdv_69b5cc9769682slideNumberDisplay = document.getElementById("gdv_69b5cc9769682slideNumber"); const gdv_69b5cc9769682imageName = document.getElementById("gdv_69b5cc9769682imageName");
let gdv_69b5cc9769682currentSlideIndex = 0;
gdv_69b5cc9769682brightnessInput.addEventListener("input", gdv_69b5cc9769682drawImage); gdv_69b5cc9769682contrastInput.addEventListener("input", gdv_69b5cc9769682drawImage);
const gdv_69b5cc9769682imageUrls = [{"url":"https:\/\/drive.google.com\/thumbnail?id=1btv9X1oGl_lr0rVlt5J2znhhlWdAlSm6&sz=w3000","name":"EPOL_LFS_sur la loi relative aux personnes qui refusent de servir ou de remettre leurs armes.jpg"}];
let gdv_69b5cc9769682scale = 1; let gdv_69b5cc9769682originX = 0; let gdv_69b5cc9769682originY = 0; const gdv_69b5cc9769682minScale = 0.1; const gdv_69b5cc9769682maxScale = 5; let gdv_69b5cc9769682currentImage = new Image();
let gdv_69b5cc9769682rotationAngle = 0;
gdv_69b5cc9769682rotateRightButton.addEventListener("click", function() { gdv_69b5cc9769682rotationAngle = (gdv_69b5cc9769682rotationAngle + 90) % 360; gdv_69b5cc9769682drawImage(); });
gdv_69b5cc9769682rotateLeftButton.addEventListener("click", function() { gdv_69b5cc9769682rotationAngle = (gdv_69b5cc9769682rotationAngle - 90 + 360) % 360; gdv_69b5cc9769682drawImage(); });
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_69b5cc9769682currentImage.src = gdv_69b5cc9769682imageUrls[0]["url"]; gdv_69b5cc9769682imageName.innerHTML = filtrerChaine(gdv_69b5cc9769682imageUrls[0]["name"], "rien"); gdv_69b5cc9769682currentImage.onload = function() {
gdv_69b5cc9769682updateSlideNumber(); gdv_69b5cc9769682resizeCanvas(); gdv_69b5cc9769682drawImage(); document.getElementById("gdv_69b5cc9769682controls").style.display = "block"; };
function gdv_69b5cc9769682updateSlideNumber() { gdv_69b5cc9769682slideNumberDisplay.textContent = `${gdv_69b5cc9769682currentSlideIndex + 1} / ${gdv_69b5cc9769682imageUrls.length}`; }
gdv_69b5cc9769682prevSlideButton.addEventListener("click", function() { if (gdv_69b5cc9769682currentSlideIndex > 0) { gdv_69b5cc9769682currentSlideIndex--; gdv_69b5cc9769682loadImage(gdv_69b5cc9769682currentSlideIndex); gdv_69b5cc9769682updateSlideNumber(); } });
gdv_69b5cc9769682nextSlideButton.addEventListener("click", function() { if (gdv_69b5cc9769682currentSlideIndex < gdv_69b5cc9769682imageUrls.length - 1) { gdv_69b5cc9769682currentSlideIndex++; gdv_69b5cc9769682loadImage(gdv_69b5cc9769682currentSlideIndex); gdv_69b5cc9769682updateSlideNumber(); } }); function gdv_69b5cc9769682resizeCanvas() { // Ajuster la taille du canvas pour correspondre à celle du conteneur const container = document.getElementById("gdv_69b5cc9769682canvasContainer"); gdv_69b5cc9769682canvas.width = container.clientWidth; gdv_69b5cc9769682canvas.height = container.clientHeight - 30; gdv_69b5cc9769682fitImageToCanvas(); // Redessiner le contenu du canvas ici gdv_69b5cc9769682drawImage(); } window.addEventListener("load", gdv_69b5cc9769682resizeCanvas); window.addEventListener("resize", gdv_69b5cc9769682resizeCanvas); function gdv_69b5cc9769682fitImageToCanvas() { const canvasAspect = gdv_69b5cc9769682canvas.width / gdv_69b5cc9769682canvas.height; const imageAspect = gdv_69b5cc9769682currentImage.width / gdv_69b5cc9769682currentImage.height; if (imageAspect > canvasAspect) { gdv_69b5cc9769682scale = gdv_69b5cc9769682canvas.width / gdv_69b5cc9769682currentImage.width; } else { gdv_69b5cc9769682scale = gdv_69b5cc9769682canvas.height / gdv_69b5cc9769682currentImage.height; } gdv_69b5cc9769682originX = gdv_69b5cc9769682canvas.width / 2; gdv_69b5cc9769682originY = gdv_69b5cc9769682canvas.height / 2; }
function gdv_69b5cc9769682drawImage() { gdv_69b5cc9769682ctx.clearRect(0, 0, gdv_69b5cc9769682canvas.width, gdv_69b5cc9769682canvas.height); gdv_69b5cc9769682ctx.save(); gdv_69b5cc9769682ctx.translate(gdv_69b5cc9769682originX, gdv_69b5cc9769682originY); gdv_69b5cc9769682ctx.rotate((Math.PI / 180) * gdv_69b5cc9769682rotationAngle); gdv_69b5cc9769682ctx.scale(gdv_69b5cc9769682scale, gdv_69b5cc9769682scale);
// Appliquer la luminosité et le contraste gdv_69b5cc9769682ctx.filter = `brightness(${gdv_69b5cc9769682brightnessInput.value}) contrast(${gdv_69b5cc9769682contrastInput.value})`; gdv_69b5cc9769682ctx.drawImage(gdv_69b5cc9769682currentImage, -gdv_69b5cc9769682currentImage.width/2, -gdv_69b5cc9769682currentImage.height/2); gdv_69b5cc9769682ctx.restore(); }
// Ajouter les miniatures des images gdv_69b5cc9769682imageUrls.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_69b5cc9769682loadImage(index); gdv_69b5cc9769682currentSlideIndex = index; gdv_69b5cc9769682updateSlideNumber(); }; slide.appendChild(img); gdv_69b5cc9769682thumbnailContainerWrapper.appendChild(slide); });
// Charger une image dans le canvas function gdv_69b5cc9769682loadImage(index) { gdv_69b5cc9769682currentImage.src = gdv_69b5cc9769682imageUrls[index]["url"]; gdv_69b5cc9769682imageName.innerHTML = filtrerChaine(gdv_69b5cc9769682imageUrls[index]["name"], "rien"); gdv_69b5cc9769682currentImage.onload = function() { gdv_69b5cc9769682scale = 1; gdv_69b5cc9769682originX = 0; gdv_69b5cc9769682originY = 0; gdv_69b5cc9769682fitImageToCanvas(); gdv_69b5cc9769682drawImage(); };
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_69b5cc9769682swiper = new Swiper(".gdv_69b5cc9769682swiper-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_69b5cc9769682swiper.on("slideChange", function () { // gdv_69b5cc9769682currentSlideIndex = gdv_69b5cc9769682swiper.activeIndex; // gdv_69b5cc9769682updateSlideNumber(); //});
// Plein écran gdv_69b5cc9769682fullscreenButton.addEventListener("click", function() { if (!document.fullscreenElement) { document.getElementById("gdv_69b5cc9769682gd-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_69b5cc9769682canvas.addEventListener("wheel", function(event) { event.preventDefault(); const zoomFactor = 0.025; const mouseX = event.offsetX; const mouseY = event.offsetY;
let newScale = gdv_69b5cc9769682scale; if (event.deltaY < 0) { newScale *= 1 + zoomFactor; } else { newScale /= 1 + zoomFactor; } newScale = Math.max(gdv_69b5cc9769682minScale, Math.min(gdv_69b5cc9769682maxScale, newScale)); const scaleRatio = newScale / gdv_69b5cc9769682scale; gdv_69b5cc9769682originX = mouseX - (mouseX - gdv_69b5cc9769682originX) * scaleRatio; gdv_69b5cc9769682originY = mouseY - (mouseY - gdv_69b5cc9769682originY) * scaleRatio; gdv_69b5cc9769682scale = newScale; gdv_69b5cc9769682drawImage(); }); // Gestion du déplacement (pan) let gdv_69b5cc9769682isDragging = false; let gdv_69b5cc9769682startX, gdv_69b5cc9769682startY; gdv_69b5cc9769682canvas.addEventListener("mousedown", function(event) { gdv_69b5cc9769682isDragging = true; gdv_69b5cc9769682startX = event.offsetX - gdv_69b5cc9769682originX; gdv_69b5cc9769682startY = event.offsetY - gdv_69b5cc9769682originY; gdv_69b5cc9769682canvas.style.cursor = "grabbing"; }); gdv_69b5cc9769682canvas.addEventListener("mousemove", function(event) { if (gdv_69b5cc9769682isDragging) { gdv_69b5cc9769682originX = event.offsetX - gdv_69b5cc9769682startX; gdv_69b5cc9769682originY = event.offsetY - gdv_69b5cc9769682startY; gdv_69b5cc9769682drawImage(); } }); // Gestion des événements tactiles gdv_69b5cc9769682canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 1) { gdv_69b5cc9769682isDragging = true; const touch = event.touches[0]; gdv_69b5cc9769682startX = touch.pageX - gdv_69b5cc9769682originX; gdv_69b5cc9769682startY = touch.pageY - gdv_69b5cc9769682originY; } }); gdv_69b5cc9769682canvas.addEventListener("touchmove", function(event) { event.preventDefault(); // Empêche le comportement par défaut du navigateur const touch = event.touches[0]; gdv_69b5cc9769682originX = touch.pageX - gdv_69b5cc9769682startX; gdv_69b5cc9769682originY = touch.pageY - gdv_69b5cc9769682startY; gdv_69b5cc9769682drawImage(); }); gdv_69b5cc9769682canvas.addEventListener("touchend", function() { gdv_69b5cc9769682isDragging = false; }); gdv_69b5cc9769682canvas.addEventListener("mouseup", function() { gdv_69b5cc9769682isDragging = false; gdv_69b5cc9769682canvas.style.cursor = "grab"; }); gdv_69b5cc9769682canvas.addEventListener("mouseleave", function() { gdv_69b5cc9769682isDragging = false; gdv_69b5cc9769682canvas.style.cursor = "grab"; }); gdv_69b5cc9769682zoomInButton.addEventListener("click", function() { let newScale = gdv_69b5cc9769682scale; const zoomFactor = 0.025; newScale *= 1 + zoomFactor; gdv_69b5cc9769682scale = Math.max(gdv_69b5cc9769682minScale, Math.min(gdv_69b5cc9769682maxScale, newScale)); gdv_69b5cc9769682drawImage(); }); gdv_69b5cc9769682zoomOutButton.addEventListener("click", function() { let newScale = gdv_69b5cc9769682scale; const zoomFactor = 0.025; newScale /= 1 + zoomFactor; gdv_69b5cc9769682scale = Math.max(gdv_69b5cc9769682minScale, Math.min(gdv_69b5cc9769682maxScale, newScale)); gdv_69b5cc9769682drawImage(); }); gdv_69b5cc9769682resetZoomButton.addEventListener("click", function() { gdv_69b5cc9769682rotationAngle = 0; gdv_69b5cc9769682fitImageToCanvas(); gdv_69b5cc9769682drawImage(); }); function gdv_69b5cc9769682getImageIdFromUrl(url) { const urlObj = new URL(url); return urlObj.searchParams.get("id"); } document.getElementById("gdv_69b5cc9769682downloadImage").addEventListener("click", function() { let url = gdv_69b5cc9769682currentImage.src; const imageId = gdv_69b5cc9769682getImageIdFromUrl(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_69b5cc9769682printImageFromApi(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_69b5cc9769682printButton = document.getElementById("gdv_69b5cc9769682printCanvas");
gdv_69b5cc9769682printButton.addEventListener("click", function() { let url = gdv_69b5cc9769682currentImage.src; const imageId = gdv_69b5cc9769682getImageIdFromUrl(url); gdv_69b5cc9769682printImageFromApi(imageId); });
let gdv_69b5cc9769682initialDistance = 0; let gdv_69b5cc9769682initialScale = 1;
gdv_69b5cc9769682canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 2) { event.preventDefault(); gdv_69b5cc9769682initialDistance = getDistance(event.touches[0], event.touches[1]); gdv_69b5cc9769682initialScale = gdv_69b5cc9769682scale; } });
gdv_69b5cc9769682canvas.addEventListener("touchmove", function(event) { if (event.touches.length === 2) { event.preventDefault(); const currentDistance = getDistance(event.touches[0], event.touches[1]); const scaleChange = currentDistance / gdv_69b5cc9769682initialDistance; let newScale = gdv_69b5cc9769682initialScale * scaleChange;
newScale = Math.max(gdv_69b5cc9769682minScale, Math.min(gdv_69b5cc9769682maxScale, 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_69b5cc9769682scale; gdv_69b5cc9769682originX = centerX - (centerX - gdv_69b5cc9769682originX) * scaleRatio; gdv_69b5cc9769682originY = centerY - (centerY - gdv_69b5cc9769682originY) * scaleRatio;
gdv_69b5cc9769682scale = newScale; gdv_69b5cc9769682drawImage(); // 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); }