1 / X
const gdv_69645730998f1canvas = document.getElementById("gdv_69645730998f1imageCanvas"); const gdv_69645730998f1ctx = gdv_69645730998f1canvas.getContext("2d");
const gdv_69645730998f1thumbnailContainer = document.getElementById("gdv_69645730998f1thumbnailContainer"); const gdv_69645730998f1thumbnailContainerWrapper = document.getElementById("gdv_69645730998f1thumbnailContainerWrapper"); const gdv_69645730998f1zoomInButton = document.getElementById("gdv_69645730998f1zoomIn"); const gdv_69645730998f1zoomOutButton = document.getElementById("gdv_69645730998f1zoomOut"); const gdv_69645730998f1resetZoomButton = document.getElementById("gdv_69645730998f1resetZoom");
const gdv_69645730998f1brightnessInput = document.getElementById("gdv_69645730998f1brightness"); const gdv_69645730998f1contrastInput = document.getElementById("gdv_69645730998f1contrast"); const gdv_69645730998f1fullscreenButton = document.getElementById("gdv_69645730998f1fullscreen");
const gdv_69645730998f1rotateRightButton = document.getElementById("gdv_69645730998f1rotateRight"); const gdv_69645730998f1rotateLeftButton = document.getElementById("gdv_69645730998f1rotateLeft");
const gdv_69645730998f1prevSlideButton = document.getElementById("gdv_69645730998f1prevSlide"); const gdv_69645730998f1nextSlideButton = document.getElementById("gdv_69645730998f1nextSlide"); const gdv_69645730998f1slideNumberDisplay = document.getElementById("gdv_69645730998f1slideNumber"); const gdv_69645730998f1imageName = document.getElementById("gdv_69645730998f1imageName");
let gdv_69645730998f1currentSlideIndex = 0;
gdv_69645730998f1brightnessInput.addEventListener("input", gdv_69645730998f1drawImage); gdv_69645730998f1contrastInput.addEventListener("input", gdv_69645730998f1drawImage);
const gdv_69645730998f1imageUrls = [{"url":"https:\/\/drive.google.com\/thumbnail?id=1dfbuPTOdmMnyRG-9Ze6ShpQndSJxiXGe&sz=w3000","name":"EPOL_ordre d'arrestation de Rollain, Cotelle et Esnault.jpg"}];
let gdv_69645730998f1scale = 1; let gdv_69645730998f1originX = 0; let gdv_69645730998f1originY = 0; const gdv_69645730998f1minScale = 0.1; const gdv_69645730998f1maxScale = 5; let gdv_69645730998f1currentImage = new Image();
let gdv_69645730998f1rotationAngle = 0;
gdv_69645730998f1rotateRightButton.addEventListener("click", function() { gdv_69645730998f1rotationAngle = (gdv_69645730998f1rotationAngle + 90) % 360; gdv_69645730998f1drawImage(); });
gdv_69645730998f1rotateLeftButton.addEventListener("click", function() { gdv_69645730998f1rotationAngle = (gdv_69645730998f1rotationAngle - 90 + 360) % 360; gdv_69645730998f1drawImage(); });
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_69645730998f1currentImage.src = gdv_69645730998f1imageUrls[0]["url"]; gdv_69645730998f1imageName.innerHTML = filtrerChaine(gdv_69645730998f1imageUrls[0]["name"], "rien"); gdv_69645730998f1currentImage.onload = function() {
gdv_69645730998f1updateSlideNumber(); gdv_69645730998f1resizeCanvas(); gdv_69645730998f1drawImage(); document.getElementById("gdv_69645730998f1controls").style.display = "block"; };
function gdv_69645730998f1updateSlideNumber() { gdv_69645730998f1slideNumberDisplay.textContent = `${gdv_69645730998f1currentSlideIndex + 1} / ${gdv_69645730998f1imageUrls.length}`; }
gdv_69645730998f1prevSlideButton.addEventListener("click", function() { if (gdv_69645730998f1currentSlideIndex > 0) { gdv_69645730998f1currentSlideIndex--; gdv_69645730998f1loadImage(gdv_69645730998f1currentSlideIndex); gdv_69645730998f1updateSlideNumber(); } });
gdv_69645730998f1nextSlideButton.addEventListener("click", function() { if (gdv_69645730998f1currentSlideIndex < gdv_69645730998f1imageUrls.length - 1) { gdv_69645730998f1currentSlideIndex++; gdv_69645730998f1loadImage(gdv_69645730998f1currentSlideIndex); gdv_69645730998f1updateSlideNumber(); } }); function gdv_69645730998f1resizeCanvas() { // Ajuster la taille du canvas pour correspondre à celle du conteneur const container = document.getElementById("gdv_69645730998f1canvasContainer"); gdv_69645730998f1canvas.width = container.clientWidth; gdv_69645730998f1canvas.height = container.clientHeight - 30; gdv_69645730998f1fitImageToCanvas(); // Redessiner le contenu du canvas ici gdv_69645730998f1drawImage(); } window.addEventListener("load", gdv_69645730998f1resizeCanvas); window.addEventListener("resize", gdv_69645730998f1resizeCanvas); function gdv_69645730998f1fitImageToCanvas() { const canvasAspect = gdv_69645730998f1canvas.width / gdv_69645730998f1canvas.height; const imageAspect = gdv_69645730998f1currentImage.width / gdv_69645730998f1currentImage.height; if (imageAspect > canvasAspect) { gdv_69645730998f1scale = gdv_69645730998f1canvas.width / gdv_69645730998f1currentImage.width; } else { gdv_69645730998f1scale = gdv_69645730998f1canvas.height / gdv_69645730998f1currentImage.height; } gdv_69645730998f1originX = gdv_69645730998f1canvas.width / 2; gdv_69645730998f1originY = gdv_69645730998f1canvas.height / 2; }
function gdv_69645730998f1drawImage() { gdv_69645730998f1ctx.clearRect(0, 0, gdv_69645730998f1canvas.width, gdv_69645730998f1canvas.height); gdv_69645730998f1ctx.save(); gdv_69645730998f1ctx.translate(gdv_69645730998f1originX, gdv_69645730998f1originY); gdv_69645730998f1ctx.rotate((Math.PI / 180) * gdv_69645730998f1rotationAngle); gdv_69645730998f1ctx.scale(gdv_69645730998f1scale, gdv_69645730998f1scale);
// Appliquer la luminosité et le contraste gdv_69645730998f1ctx.filter = `brightness(${gdv_69645730998f1brightnessInput.value}) contrast(${gdv_69645730998f1contrastInput.value})`; gdv_69645730998f1ctx.drawImage(gdv_69645730998f1currentImage, -gdv_69645730998f1currentImage.width/2, -gdv_69645730998f1currentImage.height/2); gdv_69645730998f1ctx.restore(); }
// Ajouter les miniatures des images gdv_69645730998f1imageUrls.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_69645730998f1loadImage(index); gdv_69645730998f1currentSlideIndex = index; gdv_69645730998f1updateSlideNumber(); }; slide.appendChild(img); gdv_69645730998f1thumbnailContainerWrapper.appendChild(slide); });
// Charger une image dans le canvas function gdv_69645730998f1loadImage(index) { gdv_69645730998f1currentImage.src = gdv_69645730998f1imageUrls[index]["url"]; gdv_69645730998f1imageName.innerHTML = filtrerChaine(gdv_69645730998f1imageUrls[index]["name"], "rien"); gdv_69645730998f1currentImage.onload = function() { gdv_69645730998f1scale = 1; gdv_69645730998f1originX = 0; gdv_69645730998f1originY = 0; gdv_69645730998f1fitImageToCanvas(); gdv_69645730998f1drawImage(); };
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_69645730998f1swiper = new Swiper(".gdv_69645730998f1swiper-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_69645730998f1swiper.on("slideChange", function () { // gdv_69645730998f1currentSlideIndex = gdv_69645730998f1swiper.activeIndex; // gdv_69645730998f1updateSlideNumber(); //});
// Plein écran gdv_69645730998f1fullscreenButton.addEventListener("click", function() { if (!document.fullscreenElement) { document.getElementById("gdv_69645730998f1gd-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_69645730998f1canvas.addEventListener("wheel", function(event) { event.preventDefault(); const zoomFactor = 0.025; const mouseX = event.offsetX; const mouseY = event.offsetY;
let newScale = gdv_69645730998f1scale; if (event.deltaY < 0) { newScale *= 1 + zoomFactor; } else { newScale /= 1 + zoomFactor; } newScale = Math.max(gdv_69645730998f1minScale, Math.min(gdv_69645730998f1maxScale, newScale)); const scaleRatio = newScale / gdv_69645730998f1scale; gdv_69645730998f1originX = mouseX - (mouseX - gdv_69645730998f1originX) * scaleRatio; gdv_69645730998f1originY = mouseY - (mouseY - gdv_69645730998f1originY) * scaleRatio; gdv_69645730998f1scale = newScale; gdv_69645730998f1drawImage(); }); // Gestion du déplacement (pan) let gdv_69645730998f1isDragging = false; let gdv_69645730998f1startX, gdv_69645730998f1startY; gdv_69645730998f1canvas.addEventListener("mousedown", function(event) { gdv_69645730998f1isDragging = true; gdv_69645730998f1startX = event.offsetX - gdv_69645730998f1originX; gdv_69645730998f1startY = event.offsetY - gdv_69645730998f1originY; gdv_69645730998f1canvas.style.cursor = "grabbing"; }); gdv_69645730998f1canvas.addEventListener("mousemove", function(event) { if (gdv_69645730998f1isDragging) { gdv_69645730998f1originX = event.offsetX - gdv_69645730998f1startX; gdv_69645730998f1originY = event.offsetY - gdv_69645730998f1startY; gdv_69645730998f1drawImage(); } }); // Gestion des événements tactiles gdv_69645730998f1canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 1) { gdv_69645730998f1isDragging = true; const touch = event.touches[0]; gdv_69645730998f1startX = touch.pageX - gdv_69645730998f1originX; gdv_69645730998f1startY = touch.pageY - gdv_69645730998f1originY; } }); gdv_69645730998f1canvas.addEventListener("touchmove", function(event) { event.preventDefault(); // Empêche le comportement par défaut du navigateur const touch = event.touches[0]; gdv_69645730998f1originX = touch.pageX - gdv_69645730998f1startX; gdv_69645730998f1originY = touch.pageY - gdv_69645730998f1startY; gdv_69645730998f1drawImage(); }); gdv_69645730998f1canvas.addEventListener("touchend", function() { gdv_69645730998f1isDragging = false; }); gdv_69645730998f1canvas.addEventListener("mouseup", function() { gdv_69645730998f1isDragging = false; gdv_69645730998f1canvas.style.cursor = "grab"; }); gdv_69645730998f1canvas.addEventListener("mouseleave", function() { gdv_69645730998f1isDragging = false; gdv_69645730998f1canvas.style.cursor = "grab"; }); gdv_69645730998f1zoomInButton.addEventListener("click", function() { let newScale = gdv_69645730998f1scale; const zoomFactor = 0.025; newScale *= 1 + zoomFactor; gdv_69645730998f1scale = Math.max(gdv_69645730998f1minScale, Math.min(gdv_69645730998f1maxScale, newScale)); gdv_69645730998f1drawImage(); }); gdv_69645730998f1zoomOutButton.addEventListener("click", function() { let newScale = gdv_69645730998f1scale; const zoomFactor = 0.025; newScale /= 1 + zoomFactor; gdv_69645730998f1scale = Math.max(gdv_69645730998f1minScale, Math.min(gdv_69645730998f1maxScale, newScale)); gdv_69645730998f1drawImage(); }); gdv_69645730998f1resetZoomButton.addEventListener("click", function() { gdv_69645730998f1rotationAngle = 0; gdv_69645730998f1fitImageToCanvas(); gdv_69645730998f1drawImage(); }); function gdv_69645730998f1getImageIdFromUrl(url) { const urlObj = new URL(url); return urlObj.searchParams.get("id"); } document.getElementById("gdv_69645730998f1downloadImage").addEventListener("click", function() { let url = gdv_69645730998f1currentImage.src; const imageId = gdv_69645730998f1getImageIdFromUrl(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_69645730998f1printImageFromApi(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_69645730998f1printButton = document.getElementById("gdv_69645730998f1printCanvas");
gdv_69645730998f1printButton.addEventListener("click", function() { let url = gdv_69645730998f1currentImage.src; const imageId = gdv_69645730998f1getImageIdFromUrl(url); gdv_69645730998f1printImageFromApi(imageId); });
let gdv_69645730998f1initialDistance = 0; let gdv_69645730998f1initialScale = 1;
gdv_69645730998f1canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 2) { event.preventDefault(); gdv_69645730998f1initialDistance = getDistance(event.touches[0], event.touches[1]); gdv_69645730998f1initialScale = gdv_69645730998f1scale; } });
gdv_69645730998f1canvas.addEventListener("touchmove", function(event) { if (event.touches.length === 2) { event.preventDefault(); const currentDistance = getDistance(event.touches[0], event.touches[1]); const scaleChange = currentDistance / gdv_69645730998f1initialDistance; let newScale = gdv_69645730998f1initialScale * scaleChange;
newScale = Math.max(gdv_69645730998f1minScale, Math.min(gdv_69645730998f1maxScale, 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_69645730998f1scale; gdv_69645730998f1originX = centerX - (centerX - gdv_69645730998f1originX) * scaleRatio; gdv_69645730998f1originY = centerY - (centerY - gdv_69645730998f1originY) * scaleRatio;
gdv_69645730998f1scale = newScale; gdv_69645730998f1drawImage(); // 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); }