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
if (imageElement) {
imageElement.removeAttribute('clip-path');
}
try {
const dataUrl = await domtoimage.toPng(node, {
style: { style: {
border: "none", border: "none",
padding: "0", padding: "0",
margin: "0", margin: "0",
outline: "none", outline: "none",
}, },
}) });
.then((dataUrl: string) => { const link = document.createElement("a");
var link = document.createElement("a");
link.download = "avatar.png"; link.download = "avatar.png";
link.href = dataUrl; link.href = dataUrl;
link.click(); link.click();
}); } finally {
// Restore the clip-path for the UI to keep the circle
if (imageElement) {
imageElement.setAttribute('clip-path', 'url(#circle-clip)');
}
} }
} }