1 / X
const gdv_67d32f68c84a8canvas = document.getElementById("gdv_67d32f68c84a8imageCanvas"); const gdv_67d32f68c84a8ctx = gdv_67d32f68c84a8canvas.getContext("2d");
const gdv_67d32f68c84a8thumbnailContainer = document.getElementById("gdv_67d32f68c84a8thumbnailContainer"); const gdv_67d32f68c84a8thumbnailContainerWrapper = document.getElementById("gdv_67d32f68c84a8thumbnailContainerWrapper"); const gdv_67d32f68c84a8zoomInButton = document.getElementById("gdv_67d32f68c84a8zoomIn"); const gdv_67d32f68c84a8zoomOutButton = document.getElementById("gdv_67d32f68c84a8zoomOut"); const gdv_67d32f68c84a8resetZoomButton = document.getElementById("gdv_67d32f68c84a8resetZoom");
const gdv_67d32f68c84a8brightnessInput = document.getElementById("gdv_67d32f68c84a8brightness"); const gdv_67d32f68c84a8contrastInput = document.getElementById("gdv_67d32f68c84a8contrast"); const gdv_67d32f68c84a8fullscreenButton = document.getElementById("gdv_67d32f68c84a8fullscreen");
const gdv_67d32f68c84a8rotateRightButton = document.getElementById("gdv_67d32f68c84a8rotateRight"); const gdv_67d32f68c84a8rotateLeftButton = document.getElementById("gdv_67d32f68c84a8rotateLeft");
const gdv_67d32f68c84a8prevSlideButton = document.getElementById("gdv_67d32f68c84a8prevSlide"); const gdv_67d32f68c84a8nextSlideButton = document.getElementById("gdv_67d32f68c84a8nextSlide"); const gdv_67d32f68c84a8slideNumberDisplay = document.getElementById("gdv_67d32f68c84a8slideNumber"); const gdv_67d32f68c84a8imageName = document.getElementById("gdv_67d32f68c84a8imageName");
let gdv_67d32f68c84a8currentSlideIndex = 0;
gdv_67d32f68c84a8brightnessInput.addEventListener("input", gdv_67d32f68c84a8drawImage); gdv_67d32f68c84a8contrastInput.addEventListener("input", gdv_67d32f68c84a8drawImage);
const gdv_67d32f68c84a8imageUrls = [{"url":"https:\/\/drive.google.com\/thumbnail?id=1LvXeWTtvmPnUIhbX5hbWrUZz-ehXbdLO&sz=w3000","name":"Quittance du commissaire civil pour un mois de traitement, (1er ou 7) janvier 1794.jpg"}];
let gdv_67d32f68c84a8scale = 1; let gdv_67d32f68c84a8originX = 0; let gdv_67d32f68c84a8originY = 0; const gdv_67d32f68c84a8minScale = 0.1; const gdv_67d32f68c84a8maxScale = 5; let gdv_67d32f68c84a8currentImage = new Image();
let gdv_67d32f68c84a8rotationAngle = 0;
gdv_67d32f68c84a8rotateRightButton.addEventListener("click", function() { gdv_67d32f68c84a8rotationAngle = (gdv_67d32f68c84a8rotationAngle + 90) % 360; gdv_67d32f68c84a8drawImage(); });
gdv_67d32f68c84a8rotateLeftButton.addEventListener("click", function() { gdv_67d32f68c84a8rotationAngle = (gdv_67d32f68c84a8rotationAngle - 90 + 360) % 360; gdv_67d32f68c84a8drawImage(); });
// Charger la première image par défaut gdv_67d32f68c84a8currentImage.src = gdv_67d32f68c84a8imageUrls[0]["url"]; gdv_67d32f68c84a8imageName.innerHTML = gdv_67d32f68c84a8imageUrls[0]["name"]; gdv_67d32f68c84a8currentImage.onload = function() {
gdv_67d32f68c84a8updateSlideNumber(); gdv_67d32f68c84a8resizeCanvas(); gdv_67d32f68c84a8drawImage(); document.getElementById("gdv_67d32f68c84a8controls").style.display = "block"; };
function gdv_67d32f68c84a8updateSlideNumber() { gdv_67d32f68c84a8slideNumberDisplay.textContent = `${gdv_67d32f68c84a8currentSlideIndex + 1} / ${gdv_67d32f68c84a8imageUrls.length}`; }
gdv_67d32f68c84a8prevSlideButton.addEventListener("click", function() { if (gdv_67d32f68c84a8currentSlideIndex > 0) { gdv_67d32f68c84a8currentSlideIndex--; gdv_67d32f68c84a8loadImage(gdv_67d32f68c84a8currentSlideIndex); gdv_67d32f68c84a8updateSlideNumber(); } });
gdv_67d32f68c84a8nextSlideButton.addEventListener("click", function() { if (gdv_67d32f68c84a8currentSlideIndex < gdv_67d32f68c84a8imageUrls.length - 1) { gdv_67d32f68c84a8currentSlideIndex++; gdv_67d32f68c84a8loadImage(gdv_67d32f68c84a8currentSlideIndex); gdv_67d32f68c84a8updateSlideNumber(); } }); function gdv_67d32f68c84a8resizeCanvas() { // Ajuster la taille du canvas pour correspondre à celle du conteneur const container = document.getElementById("gdv_67d32f68c84a8canvasContainer"); gdv_67d32f68c84a8canvas.width = container.clientWidth; gdv_67d32f68c84a8canvas.height = container.clientHeight - 30; gdv_67d32f68c84a8fitImageToCanvas(); // Redessiner le contenu du canvas ici gdv_67d32f68c84a8drawImage(); } window.addEventListener("load", gdv_67d32f68c84a8resizeCanvas); window.addEventListener("resize", gdv_67d32f68c84a8resizeCanvas); function gdv_67d32f68c84a8fitImageToCanvas() { const canvasAspect = gdv_67d32f68c84a8canvas.width / gdv_67d32f68c84a8canvas.height; const imageAspect = gdv_67d32f68c84a8currentImage.width / gdv_67d32f68c84a8currentImage.height; if (imageAspect > canvasAspect) { gdv_67d32f68c84a8scale = gdv_67d32f68c84a8canvas.width / gdv_67d32f68c84a8currentImage.width; } else { gdv_67d32f68c84a8scale = gdv_67d32f68c84a8canvas.height / gdv_67d32f68c84a8currentImage.height; } gdv_67d32f68c84a8originX = gdv_67d32f68c84a8canvas.width / 2; gdv_67d32f68c84a8originY = gdv_67d32f68c84a8canvas.height / 2; }
function gdv_67d32f68c84a8drawImage() { gdv_67d32f68c84a8ctx.clearRect(0, 0, gdv_67d32f68c84a8canvas.width, gdv_67d32f68c84a8canvas.height); gdv_67d32f68c84a8ctx.save(); gdv_67d32f68c84a8ctx.translate(gdv_67d32f68c84a8originX, gdv_67d32f68c84a8originY); gdv_67d32f68c84a8ctx.rotate((Math.PI / 180) * gdv_67d32f68c84a8rotationAngle); gdv_67d32f68c84a8ctx.scale(gdv_67d32f68c84a8scale, gdv_67d32f68c84a8scale);
// Appliquer la luminosité et le contraste gdv_67d32f68c84a8ctx.filter = `brightness(${gdv_67d32f68c84a8brightnessInput.value}) contrast(${gdv_67d32f68c84a8contrastInput.value})`; gdv_67d32f68c84a8ctx.drawImage(gdv_67d32f68c84a8currentImage, -gdv_67d32f68c84a8currentImage.width/2, -gdv_67d32f68c84a8currentImage.height/2); gdv_67d32f68c84a8ctx.restore(); }
// Ajouter les miniatures des images gdv_67d32f68c84a8imageUrls.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_67d32f68c84a8loadImage(index); gdv_67d32f68c84a8currentSlideIndex = index; gdv_67d32f68c84a8updateSlideNumber(); }; slide.appendChild(img); gdv_67d32f68c84a8thumbnailContainerWrapper.appendChild(slide); });
// Charger une image dans le canvas function gdv_67d32f68c84a8loadImage(index) { gdv_67d32f68c84a8currentImage.src = gdv_67d32f68c84a8imageUrls[index]["url"]; gdv_67d32f68c84a8imageName.innerHTML = gdv_67d32f68c84a8imageUrls[index]["name"]; gdv_67d32f68c84a8currentImage.onload = function() { gdv_67d32f68c84a8scale = 1; gdv_67d32f68c84a8originX = 0; gdv_67d32f68c84a8originY = 0; gdv_67d32f68c84a8fitImageToCanvas(); gdv_67d32f68c84a8drawImage(); }; }
// Initialiser Swiper var gdv_67d32f68c84a8swiper = new Swiper(".gdv_67d32f68c84a8swiper-container", { direction: "vertical", slidesPerView: 10, spaceBetween: 10, breakpoints: { 576: { slidesPerView: 6, spaceBetween: 10 }, 768: { slidesPerView: 6, spaceBetween: 10 }, 992: { slidesPerView: 5, spaceBetween: 15 }, 1200: { slidesPerView: 5, spaceBetween: 15 } }, mousewheel: true, });
//gdv_67d32f68c84a8swiper.on("slideChange", function () { // gdv_67d32f68c84a8currentSlideIndex = gdv_67d32f68c84a8swiper.activeIndex; // gdv_67d32f68c84a8updateSlideNumber(); //});
// Plein écran gdv_67d32f68c84a8fullscreenButton.addEventListener("click", function() { if (!document.fullscreenElement) { document.getElementById("gdv_67d32f68c84a8gd-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_67d32f68c84a8canvas.addEventListener("wheel", function(event) { event.preventDefault(); const zoomFactor = 0.025; const mouseX = event.offsetX; const mouseY = event.offsetY;
let newScale = gdv_67d32f68c84a8scale; if (event.deltaY < 0) { newScale *= 1 + zoomFactor; } else { newScale /= 1 + zoomFactor; } newScale = Math.max(gdv_67d32f68c84a8minScale, Math.min(gdv_67d32f68c84a8maxScale, newScale)); const scaleRatio = newScale / gdv_67d32f68c84a8scale; gdv_67d32f68c84a8originX = mouseX - (mouseX - gdv_67d32f68c84a8originX) * scaleRatio; gdv_67d32f68c84a8originY = mouseY - (mouseY - gdv_67d32f68c84a8originY) * scaleRatio; gdv_67d32f68c84a8scale = newScale; gdv_67d32f68c84a8drawImage(); }); // Gestion du déplacement (pan) let gdv_67d32f68c84a8isDragging = false; let gdv_67d32f68c84a8startX, gdv_67d32f68c84a8startY; gdv_67d32f68c84a8canvas.addEventListener("mousedown", function(event) { gdv_67d32f68c84a8isDragging = true; gdv_67d32f68c84a8startX = event.offsetX - gdv_67d32f68c84a8originX; gdv_67d32f68c84a8startY = event.offsetY - gdv_67d32f68c84a8originY; gdv_67d32f68c84a8canvas.style.cursor = "grabbing"; }); gdv_67d32f68c84a8canvas.addEventListener("mousemove", function(event) { if (gdv_67d32f68c84a8isDragging) { gdv_67d32f68c84a8originX = event.offsetX - gdv_67d32f68c84a8startX; gdv_67d32f68c84a8originY = event.offsetY - gdv_67d32f68c84a8startY; gdv_67d32f68c84a8drawImage(); } }); // Gestion des événements tactiles gdv_67d32f68c84a8canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 1) { gdv_67d32f68c84a8isDragging = true; const touch = event.touches[0]; gdv_67d32f68c84a8startX = touch.pageX - gdv_67d32f68c84a8originX; gdv_67d32f68c84a8startY = touch.pageY - gdv_67d32f68c84a8originY; } }); gdv_67d32f68c84a8canvas.addEventListener("touchmove", function(event) { event.preventDefault(); // Empêche le comportement par défaut du navigateur const touch = event.touches[0]; gdv_67d32f68c84a8originX = touch.pageX - gdv_67d32f68c84a8startX; gdv_67d32f68c84a8originY = touch.pageY - gdv_67d32f68c84a8startY; gdv_67d32f68c84a8drawImage(); }); gdv_67d32f68c84a8canvas.addEventListener("touchend", function() { gdv_67d32f68c84a8isDragging = false; }); gdv_67d32f68c84a8canvas.addEventListener("mouseup", function() { gdv_67d32f68c84a8isDragging = false; gdv_67d32f68c84a8canvas.style.cursor = "grab"; }); gdv_67d32f68c84a8canvas.addEventListener("mouseleave", function() { gdv_67d32f68c84a8isDragging = false; gdv_67d32f68c84a8canvas.style.cursor = "grab"; }); gdv_67d32f68c84a8zoomInButton.addEventListener("click", function() { let newScale = gdv_67d32f68c84a8scale; const zoomFactor = 0.025; newScale *= 1 + zoomFactor; gdv_67d32f68c84a8scale = Math.max(gdv_67d32f68c84a8minScale, Math.min(gdv_67d32f68c84a8maxScale, newScale)); gdv_67d32f68c84a8drawImage(); }); gdv_67d32f68c84a8zoomOutButton.addEventListener("click", function() { let newScale = gdv_67d32f68c84a8scale; const zoomFactor = 0.025; newScale /= 1 + zoomFactor; gdv_67d32f68c84a8scale = Math.max(gdv_67d32f68c84a8minScale, Math.min(gdv_67d32f68c84a8maxScale, newScale)); gdv_67d32f68c84a8drawImage(); }); gdv_67d32f68c84a8resetZoomButton.addEventListener("click", function() { gdv_67d32f68c84a8rotationAngle = 0; gdv_67d32f68c84a8fitImageToCanvas(); gdv_67d32f68c84a8drawImage(); }); function gdv_67d32f68c84a8getImageIdFromUrl(url) { const urlObj = new URL(url); return urlObj.searchParams.get("id"); } document.getElementById("gdv_67d32f68c84a8downloadImage").addEventListener("click", function() { let url = gdv_67d32f68c84a8currentImage.src; const imageId = gdv_67d32f68c84a8getImageIdFromUrl(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_67d32f68c84a8printImageFromApi(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_67d32f68c84a8printButton = document.getElementById("gdv_67d32f68c84a8printCanvas");
gdv_67d32f68c84a8printButton.addEventListener("click", function() { let url = gdv_67d32f68c84a8currentImage.src; const imageId = gdv_67d32f68c84a8getImageIdFromUrl(url); gdv_67d32f68c84a8printImageFromApi(imageId); });
let gdv_67d32f68c84a8initialDistance = 0; let gdv_67d32f68c84a8initialScale = 1;
gdv_67d32f68c84a8canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 2) { event.preventDefault(); gdv_67d32f68c84a8initialDistance = getDistance(event.touches[0], event.touches[1]); gdv_67d32f68c84a8initialScale = gdv_67d32f68c84a8scale; } });
gdv_67d32f68c84a8canvas.addEventListener("touchmove", function(event) { if (event.touches.length === 2) { event.preventDefault(); const currentDistance = getDistance(event.touches[0], event.touches[1]); const scaleChange = currentDistance / gdv_67d32f68c84a8initialDistance; let newScale = gdv_67d32f68c84a8initialScale * scaleChange;
newScale = Math.max(gdv_67d32f68c84a8minScale, Math.min(gdv_67d32f68c84a8maxScale, 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_67d32f68c84a8scale; gdv_67d32f68c84a8originX = centerX - (centerX - gdv_67d32f68c84a8originX) * scaleRatio; gdv_67d32f68c84a8originY = centerY - (centerY - gdv_67d32f68c84a8originY) * scaleRatio;
gdv_67d32f68c84a8scale = newScale; gdv_67d32f68c84a8drawImage(); // 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); }