Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -48,13 +48,12 @@ def html_output(input_file):
|
|
48 |
function copySvgToClipboard() {
|
49 |
const svgElement = document.getElementById('svgElement');
|
50 |
const svgData = new XMLSerializer().serializeToString(svgElement);
|
51 |
-
const blob = new Blob([svgData], { type: 'image/svg+xml' });
|
52 |
-
const clipboardItem = [new ClipboardItem({ 'image/svg+xml': blob })];
|
53 |
|
54 |
-
|
55 |
-
|
|
|
56 |
}).catch(err => {
|
57 |
-
console.error("Could not copy SVG to clipboard: ", err);
|
58 |
});
|
59 |
}
|
60 |
|
@@ -67,19 +66,28 @@ function copyPngToClipboard() {
|
|
67 |
const img = new Image();
|
68 |
|
69 |
img.onload = function () {
|
|
|
70 |
canvas.width = svgElement.clientWidth;
|
71 |
canvas.height = svgElement.clientHeight;
|
|
|
|
|
|
|
|
|
|
|
72 |
ctx.drawImage(img, 0, 0);
|
|
|
|
|
73 |
canvas.toBlob(blob => {
|
74 |
const clipboardItem = [new ClipboardItem({ 'image/png': blob })];
|
75 |
navigator.clipboard.write(clipboardItem).then(() => {
|
76 |
-
alert("PNG copied to clipboard!");
|
77 |
}).catch(err => {
|
78 |
console.error("Could not copy PNG to clipboard: ", err);
|
79 |
});
|
80 |
}, 'image/png');
|
81 |
};
|
82 |
|
|
|
83 |
img.src = 'data:image/svg+xml;base64,' + btoa(svgData);
|
84 |
}
|
85 |
|
|
|
48 |
function copySvgToClipboard() {
|
49 |
const svgElement = document.getElementById('svgElement');
|
50 |
const svgData = new XMLSerializer().serializeToString(svgElement);
|
|
|
|
|
51 |
|
52 |
+
// Copy the serialized SVG text to the clipboard
|
53 |
+
navigator.clipboard.writeText(svgData).then(() => {
|
54 |
+
alert("SVG text copied to clipboard!");
|
55 |
}).catch(err => {
|
56 |
+
console.error("Could not copy SVG text to clipboard: ", err);
|
57 |
});
|
58 |
}
|
59 |
|
|
|
66 |
const img = new Image();
|
67 |
|
68 |
img.onload = function () {
|
69 |
+
// Ensure canvas size matches the SVG
|
70 |
canvas.width = svgElement.clientWidth;
|
71 |
canvas.height = svgElement.clientHeight;
|
72 |
+
|
73 |
+
// Clear the canvas (transparent background)
|
74 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
75 |
+
|
76 |
+
// Draw the SVG image on the canvas
|
77 |
ctx.drawImage(img, 0, 0);
|
78 |
+
|
79 |
+
// Convert the canvas content to a PNG blob
|
80 |
canvas.toBlob(blob => {
|
81 |
const clipboardItem = [new ClipboardItem({ 'image/png': blob })];
|
82 |
navigator.clipboard.write(clipboardItem).then(() => {
|
83 |
+
alert("PNG with transparent background copied to clipboard!");
|
84 |
}).catch(err => {
|
85 |
console.error("Could not copy PNG to clipboard: ", err);
|
86 |
});
|
87 |
}, 'image/png');
|
88 |
};
|
89 |
|
90 |
+
// Set the image source to the serialized SVG data
|
91 |
img.src = 'data:image/svg+xml;base64,' + btoa(svgData);
|
92 |
}
|
93 |
|