circle to squad images to save

This commit is contained in:
2025-08-29 10:09:05 +03:00
parent 6e6b0df8b8
commit c4a03cddb6

View File

@@ -75,24 +75,34 @@
async function saveImage(): Promise<void> { async function saveImage(): Promise<void> {
if (!image) return; if (!image) return;
let node = document.getElementById("result"); const node = document.getElementById("result");
if (!node) return;
if (node) { const imageElement = node.querySelector('image[clip-path]');
domtoimage
.toPng(node, { // Temporarily remove the clip-path for saving the square image
style: { if (imageElement) {
border: "none", imageElement.removeAttribute('clip-path');
padding: "0", }
margin: "0",
outline: "none", try {
}, const dataUrl = await domtoimage.toPng(node, {
}) style: {
.then((dataUrl: string) => { border: "none",
var link = document.createElement("a"); padding: "0",
link.download = "avatar.png"; margin: "0",
link.href = dataUrl; outline: "none",
link.click(); },
}); });
const link = document.createElement("a");
link.download = "avatar.png";
link.href = dataUrl;
link.click();
} finally {
// Restore the clip-path for the UI to keep the circle
if (imageElement) {
imageElement.setAttribute('clip-path', 'url(#circle-clip)');
}
} }
} }