1 / X
const gdv_68ef59491c469canvas = document.getElementById("gdv_68ef59491c469imageCanvas"); const gdv_68ef59491c469ctx = gdv_68ef59491c469canvas.getContext("2d");
const gdv_68ef59491c469thumbnailContainer = document.getElementById("gdv_68ef59491c469thumbnailContainer"); const gdv_68ef59491c469thumbnailContainerWrapper = document.getElementById("gdv_68ef59491c469thumbnailContainerWrapper"); const gdv_68ef59491c469zoomInButton = document.getElementById("gdv_68ef59491c469zoomIn"); const gdv_68ef59491c469zoomOutButton = document.getElementById("gdv_68ef59491c469zoomOut"); const gdv_68ef59491c469resetZoomButton = document.getElementById("gdv_68ef59491c469resetZoom");
const gdv_68ef59491c469brightnessInput = document.getElementById("gdv_68ef59491c469brightness"); const gdv_68ef59491c469contrastInput = document.getElementById("gdv_68ef59491c469contrast"); const gdv_68ef59491c469fullscreenButton = document.getElementById("gdv_68ef59491c469fullscreen");
const gdv_68ef59491c469rotateRightButton = document.getElementById("gdv_68ef59491c469rotateRight"); const gdv_68ef59491c469rotateLeftButton = document.getElementById("gdv_68ef59491c469rotateLeft");
const gdv_68ef59491c469prevSlideButton = document.getElementById("gdv_68ef59491c469prevSlide"); const gdv_68ef59491c469nextSlideButton = document.getElementById("gdv_68ef59491c469nextSlide"); const gdv_68ef59491c469slideNumberDisplay = document.getElementById("gdv_68ef59491c469slideNumber"); const gdv_68ef59491c469imageName = document.getElementById("gdv_68ef59491c469imageName");
let gdv_68ef59491c469currentSlideIndex = 0;
gdv_68ef59491c469brightnessInput.addEventListener("input", gdv_68ef59491c469drawImage); gdv_68ef59491c469contrastInput.addEventListener("input", gdv_68ef59491c469drawImage);
const gdv_68ef59491c469imageUrls = [{"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_68ef59491c469scale = 1; let gdv_68ef59491c469originX = 0; let gdv_68ef59491c469originY = 0; const gdv_68ef59491c469minScale = 0.1; const gdv_68ef59491c469maxScale = 5; let gdv_68ef59491c469currentImage = new Image();
let gdv_68ef59491c469rotationAngle = 0;
gdv_68ef59491c469rotateRightButton.addEventListener("click", function() { gdv_68ef59491c469rotationAngle = (gdv_68ef59491c469rotationAngle + 90) % 360; gdv_68ef59491c469drawImage(); });
gdv_68ef59491c469rotateLeftButton.addEventListener("click", function() { gdv_68ef59491c469rotationAngle = (gdv_68ef59491c469rotationAngle - 90 + 360) % 360; gdv_68ef59491c469drawImage(); });
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_68ef59491c469currentImage.src = gdv_68ef59491c469imageUrls[0]["url"]; gdv_68ef59491c469imageName.innerHTML = filtrerChaine(gdv_68ef59491c469imageUrls[0]["name"], "rien"); gdv_68ef59491c469currentImage.onload = function() {
gdv_68ef59491c469updateSlideNumber(); gdv_68ef59491c469resizeCanvas(); gdv_68ef59491c469drawImage(); document.getElementById("gdv_68ef59491c469controls").style.display = "block"; };
function gdv_68ef59491c469updateSlideNumber() { gdv_68ef59491c469slideNumberDisplay.textContent = `${gdv_68ef59491c469currentSlideIndex + 1} / ${gdv_68ef59491c469imageUrls.length}`; }
gdv_68ef59491c469prevSlideButton.addEventListener("click", function() { if (gdv_68ef59491c469currentSlideIndex > 0) { gdv_68ef59491c469currentSlideIndex--; gdv_68ef59491c469loadImage(gdv_68ef59491c469currentSlideIndex); gdv_68ef59491c469updateSlideNumber(); } });
gdv_68ef59491c469nextSlideButton.addEventListener("click", function() { if (gdv_68ef59491c469currentSlideIndex < gdv_68ef59491c469imageUrls.length - 1) { gdv_68ef59491c469currentSlideIndex++; gdv_68ef59491c469loadImage(gdv_68ef59491c469currentSlideIndex); gdv_68ef59491c469updateSlideNumber(); } }); function gdv_68ef59491c469resizeCanvas() { // Ajuster la taille du canvas pour correspondre à celle du conteneur const container = document.getElementById("gdv_68ef59491c469canvasContainer"); gdv_68ef59491c469canvas.width = container.clientWidth; gdv_68ef59491c469canvas.height = container.clientHeight - 30; gdv_68ef59491c469fitImageToCanvas(); // Redessiner le contenu du canvas ici gdv_68ef59491c469drawImage(); } window.addEventListener("load", gdv_68ef59491c469resizeCanvas); window.addEventListener("resize", gdv_68ef59491c469resizeCanvas); function gdv_68ef59491c469fitImageToCanvas() { const canvasAspect = gdv_68ef59491c469canvas.width / gdv_68ef59491c469canvas.height; const imageAspect = gdv_68ef59491c469currentImage.width / gdv_68ef59491c469currentImage.height; if (imageAspect > canvasAspect) { gdv_68ef59491c469scale = gdv_68ef59491c469canvas.width / gdv_68ef59491c469currentImage.width; } else { gdv_68ef59491c469scale = gdv_68ef59491c469canvas.height / gdv_68ef59491c469currentImage.height; } gdv_68ef59491c469originX = gdv_68ef59491c469canvas.width / 2; gdv_68ef59491c469originY = gdv_68ef59491c469canvas.height / 2; }
function gdv_68ef59491c469drawImage() { gdv_68ef59491c469ctx.clearRect(0, 0, gdv_68ef59491c469canvas.width, gdv_68ef59491c469canvas.height); gdv_68ef59491c469ctx.save(); gdv_68ef59491c469ctx.translate(gdv_68ef59491c469originX, gdv_68ef59491c469originY); gdv_68ef59491c469ctx.rotate((Math.PI / 180) * gdv_68ef59491c469rotationAngle); gdv_68ef59491c469ctx.scale(gdv_68ef59491c469scale, gdv_68ef59491c469scale);
// Appliquer la luminosité et le contraste gdv_68ef59491c469ctx.filter = `brightness(${gdv_68ef59491c469brightnessInput.value}) contrast(${gdv_68ef59491c469contrastInput.value})`; gdv_68ef59491c469ctx.drawImage(gdv_68ef59491c469currentImage, -gdv_68ef59491c469currentImage.width/2, -gdv_68ef59491c469currentImage.height/2); gdv_68ef59491c469ctx.restore(); }
// Ajouter les miniatures des images gdv_68ef59491c469imageUrls.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_68ef59491c469loadImage(index); gdv_68ef59491c469currentSlideIndex = index; gdv_68ef59491c469updateSlideNumber(); }; slide.appendChild(img); gdv_68ef59491c469thumbnailContainerWrapper.appendChild(slide); });
// Charger une image dans le canvas function gdv_68ef59491c469loadImage(index) { gdv_68ef59491c469currentImage.src = gdv_68ef59491c469imageUrls[index]["url"]; gdv_68ef59491c469imageName.innerHTML = filtrerChaine(gdv_68ef59491c469imageUrls[index]["name"], "rien"); gdv_68ef59491c469currentImage.onload = function() { gdv_68ef59491c469scale = 1; gdv_68ef59491c469originX = 0; gdv_68ef59491c469originY = 0; gdv_68ef59491c469fitImageToCanvas(); gdv_68ef59491c469drawImage(); };
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_68ef59491c469swiper = new Swiper(".gdv_68ef59491c469swiper-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_68ef59491c469swiper.on("slideChange", function () { // gdv_68ef59491c469currentSlideIndex = gdv_68ef59491c469swiper.activeIndex; // gdv_68ef59491c469updateSlideNumber(); //});
// Plein écran gdv_68ef59491c469fullscreenButton.addEventListener("click", function() { if (!document.fullscreenElement) { document.getElementById("gdv_68ef59491c469gd-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_68ef59491c469canvas.addEventListener("wheel", function(event) { event.preventDefault(); const zoomFactor = 0.025; const mouseX = event.offsetX; const mouseY = event.offsetY;
let newScale = gdv_68ef59491c469scale; if (event.deltaY < 0) { newScale *= 1 + zoomFactor; } else { newScale /= 1 + zoomFactor; } newScale = Math.max(gdv_68ef59491c469minScale, Math.min(gdv_68ef59491c469maxScale, newScale)); const scaleRatio = newScale / gdv_68ef59491c469scale; gdv_68ef59491c469originX = mouseX - (mouseX - gdv_68ef59491c469originX) * scaleRatio; gdv_68ef59491c469originY = mouseY - (mouseY - gdv_68ef59491c469originY) * scaleRatio; gdv_68ef59491c469scale = newScale; gdv_68ef59491c469drawImage(); }); // Gestion du déplacement (pan) let gdv_68ef59491c469isDragging = false; let gdv_68ef59491c469startX, gdv_68ef59491c469startY; gdv_68ef59491c469canvas.addEventListener("mousedown", function(event) { gdv_68ef59491c469isDragging = true; gdv_68ef59491c469startX = event.offsetX - gdv_68ef59491c469originX; gdv_68ef59491c469startY = event.offsetY - gdv_68ef59491c469originY; gdv_68ef59491c469canvas.style.cursor = "grabbing"; }); gdv_68ef59491c469canvas.addEventListener("mousemove", function(event) { if (gdv_68ef59491c469isDragging) { gdv_68ef59491c469originX = event.offsetX - gdv_68ef59491c469startX; gdv_68ef59491c469originY = event.offsetY - gdv_68ef59491c469startY; gdv_68ef59491c469drawImage(); } }); // Gestion des événements tactiles gdv_68ef59491c469canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 1) { gdv_68ef59491c469isDragging = true; const touch = event.touches[0]; gdv_68ef59491c469startX = touch.pageX - gdv_68ef59491c469originX; gdv_68ef59491c469startY = touch.pageY - gdv_68ef59491c469originY; } }); gdv_68ef59491c469canvas.addEventListener("touchmove", function(event) { event.preventDefault(); // Empêche le comportement par défaut du navigateur const touch = event.touches[0]; gdv_68ef59491c469originX = touch.pageX - gdv_68ef59491c469startX; gdv_68ef59491c469originY = touch.pageY - gdv_68ef59491c469startY; gdv_68ef59491c469drawImage(); }); gdv_68ef59491c469canvas.addEventListener("touchend", function() { gdv_68ef59491c469isDragging = false; }); gdv_68ef59491c469canvas.addEventListener("mouseup", function() { gdv_68ef59491c469isDragging = false; gdv_68ef59491c469canvas.style.cursor = "grab"; }); gdv_68ef59491c469canvas.addEventListener("mouseleave", function() { gdv_68ef59491c469isDragging = false; gdv_68ef59491c469canvas.style.cursor = "grab"; }); gdv_68ef59491c469zoomInButton.addEventListener("click", function() { let newScale = gdv_68ef59491c469scale; const zoomFactor = 0.025; newScale *= 1 + zoomFactor; gdv_68ef59491c469scale = Math.max(gdv_68ef59491c469minScale, Math.min(gdv_68ef59491c469maxScale, newScale)); gdv_68ef59491c469drawImage(); }); gdv_68ef59491c469zoomOutButton.addEventListener("click", function() { let newScale = gdv_68ef59491c469scale; const zoomFactor = 0.025; newScale /= 1 + zoomFactor; gdv_68ef59491c469scale = Math.max(gdv_68ef59491c469minScale, Math.min(gdv_68ef59491c469maxScale, newScale)); gdv_68ef59491c469drawImage(); }); gdv_68ef59491c469resetZoomButton.addEventListener("click", function() { gdv_68ef59491c469rotationAngle = 0; gdv_68ef59491c469fitImageToCanvas(); gdv_68ef59491c469drawImage(); }); function gdv_68ef59491c469getImageIdFromUrl(url) { const urlObj = new URL(url); return urlObj.searchParams.get("id"); } document.getElementById("gdv_68ef59491c469downloadImage").addEventListener("click", function() { let url = gdv_68ef59491c469currentImage.src; const imageId = gdv_68ef59491c469getImageIdFromUrl(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_68ef59491c469printImageFromApi(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_68ef59491c469printButton = document.getElementById("gdv_68ef59491c469printCanvas");
gdv_68ef59491c469printButton.addEventListener("click", function() { let url = gdv_68ef59491c469currentImage.src; const imageId = gdv_68ef59491c469getImageIdFromUrl(url); gdv_68ef59491c469printImageFromApi(imageId); });
let gdv_68ef59491c469initialDistance = 0; let gdv_68ef59491c469initialScale = 1;
gdv_68ef59491c469canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 2) { event.preventDefault(); gdv_68ef59491c469initialDistance = getDistance(event.touches[0], event.touches[1]); gdv_68ef59491c469initialScale = gdv_68ef59491c469scale; } });
gdv_68ef59491c469canvas.addEventListener("touchmove", function(event) { if (event.touches.length === 2) { event.preventDefault(); const currentDistance = getDistance(event.touches[0], event.touches[1]); const scaleChange = currentDistance / gdv_68ef59491c469initialDistance; let newScale = gdv_68ef59491c469initialScale * scaleChange;
newScale = Math.max(gdv_68ef59491c469minScale, Math.min(gdv_68ef59491c469maxScale, 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_68ef59491c469scale; gdv_68ef59491c469originX = centerX - (centerX - gdv_68ef59491c469originX) * scaleRatio; gdv_68ef59491c469originY = centerY - (centerY - gdv_68ef59491c469originY) * scaleRatio;
gdv_68ef59491c469scale = newScale; gdv_68ef59491c469drawImage(); // 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); }