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> {
if (!image) return;
let node = document.getElementById("result");
const node = document.getElementById("result");
if (!node) return;
if (node) {
domtoimage
.toPng(node, {
style: {
border: "none",
padding: "0",
margin: "0",
outline: "none",
},
})
.then((dataUrl: string) => {
var link = document.createElement("a");
link.download = "avatar.png";
link.href = dataUrl;
link.click();
});
const imageElement = node.querySelector('image[clip-path]');
// Temporarily remove the clip-path for saving the square image
if (imageElement) {
imageElement.removeAttribute('clip-path');
}
try {
const dataUrl = await domtoimage.toPng(node, {
style: {
border: "none",
padding: "0",
margin: "0",
outline: "none",
},
});
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)');
}
}
}