-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdom-to-image-test.html
44 lines (38 loc) · 943 Bytes
/
dom-to-image-test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<style>
#svgimage, svg {
margin: 0;
padding: 0;
}
svg {
border: solid blue 4px;
}
</style>
<div id="svgimage"></div>
<div id="previewImg">
<img />
</div>
<script type="importmap">
{
"imports": {
"dom-to-image": "https://cdn.jsdelivr.net/npm/dom-to-image/+esm"
}
}
</script>
<script type="module">
import domtoimage from "dom-to-image";
// load SVG
fetch("https://raw.githack.com/coder0107git/html2canvas-issue-2881/main/SVG3.svg")
.then(async response => await response.text())
.then(async res => document.querySelector("#svgimage").innerHTML = await res)
.then(() => {
domtoimage.toPng(document.querySelector("#svgimage svg"))
.then(dataUrl => {
let img = new Image();
img.src = dataUrl;
document.body.appendChild(img);
})
.catch(function (error) {
console.error('oops, something went wrong!', error);
});
}).catch(e => console.error(e.stack));
</script>