Embedding svg image not drawed
See original GitHub issueI have a simple page with SVG icons. When I generate the canvas element with html2canvas, the image tag is not drawed.
I tried with firefox & chrome, and changed the image size.
HTML
/* html */
<div>
<img src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sbnM6c29kaXBvZGk9Imh0dHA6Ly9zb2RpcG9kaS5zb3VyY2Vmb3JnZS5uZXQvRFREL3NvZGlwb2RpLTAuZHRkIgogICB4bWxuczppbmtzY2FwZT0iaHR0cDovL3d3dy5pbmtzY2FwZS5vcmcvbmFtZXNwYWNlcy9pbmtzY2FwZSIKICAgdmVyc2lvbj0iMS4xIgogICB4PSIwcHgiCiAgIHk9IjBweCIKICAgdmlld0JveD0iMCAwIDIwMCAyMDAiCiAgIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDIwMCAyMDAiCiAgIHhtbDpzcGFjZT0icHJlc2VydmUiCiAgIGlkPSJzdmcyIgogICBpbmtzY2FwZTp2ZXJzaW9uPSIwLjQ4LjUgcjEwMDQwIgogICB3aWR0aD0iMTAwJSIKICAgaGVpZ2h0PSIxMDAlIgogICBzb2RpcG9kaTpkb2NuYW1lPSIzMjctY3VsdHVyYS5zdmciPjxtZXRhZGF0YQogICAgIGlkPSJtZXRhZGF0YTE2Ij48cmRmOlJERj48Y2M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ogTTE1MC4xLDEwOC42ICAgIGMtNi44LTAuNi0xMC4zLTQuOC0xMC04LjJjMCwwLDQuNywxLDEwLjYsMS41YzUuOSwwLjUsMTAuNywwLjMsMTAuNywwLjNDMTYxLjEsMTA1LjcsMTU2LjksMTA5LjIsMTUwLjEsMTA4LjZ6IgogICAgICAgICBpZD0icGF0aDciIC8+PC9nPjwvZz48ZwogICAgIGlkPSJMYXllcl8xNCI+PHBvbHlnb24KICAgICAgIG9wYWNpdHk9IjAuMSIKICAgICAgIHBvaW50cz0iMTk5LjQsMjAwIDAsMjAwIDAsMTQ2LjcgMjAwLjIsNTAuNiAgIgogICAgICAgaWQ9InBvbHlnb24xMCIgLz48L2c+PC9zdmc+">
</div>
CSS:
/* CSS */
div{
width: 90px; height: 90px;
background-color: blue;
}
div img
{
width: 100%; height: auto;
}
Javascript:
jQuery(function($){
var e = $('div')[0];
html2canvas(e, { logging: true }).then(function(canvas){
$('#result').attr('src', canvas.toDataURL() );
});
});
SVG image:
<?xml version="1.0" encoding="UTF-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 200 200" enable-background="new 0 0 200 200" xml:space="preserve">
<g id="Layer_5">
<g>
<path fill="#FFFFFF" d="M136.5,76.8L102.7,71l-1.6,18.2l-2.8-31.8l-33.8,5.8l-34.3,0.1l4.3,49.1c1.6,18.8,18.2,32.7,37,31.1 c11.7-1,21.5-7.8,26.9-17.4c1.4,16.2,14.3,29.6,31.1,31c18.8,1.6,35.4-12.3,37-31.1l4.3-49.1L136.5,76.8z M40.1,93.7 c-0.3-3.4,3.2-7.6,10-8.2c6.8-0.6,11,2.9,11.3,6.3c0,0-4.8-0.2-10.7,0.3C44.8,92.7,40.1,93.7,40.1,93.7z M70.2,128.3 c-10.7,0.9-17.3-6.2-17.9-13.4c0,0,7.3-2.2,16.5-3c9.2-0.8,16.8,0.1,16.8,0.1C86.2,119.2,80.9,127.4,70.2,128.3z M83.1,89.4 c-5.9,0.5-10.6,1.5-10.6,1.5c-0.3-3.4,3.2-7.6,10-8.2c6.8-0.6,11,2.9,11.3,6.3C93.9,89,89,88.8,83.1,89.4z M107.6,97.6 c0,0,4.7,1,10.6,1.5c5.9,0.5,10.7,0.3,10.7,0.3c-0.3,3.4-4.5,6.9-11.3,6.3C110.8,105.2,107.3,101,107.6,97.6z M147.9,138.3 c0,0-7.6,0.9-16.8,0.1c-9.2-0.8-16.5-3-16.5-3c0.6-7.2,7.3-14.3,17.9-13.4C143.2,123,148.5,131.1,147.9,138.3z M150.1,108.6 c-6.8-0.6-10.3-4.8-10-8.2c0,0,4.7,1,10.6,1.5c5.9,0.5,10.7,0.3,10.7,0.3C161.1,105.7,156.9,109.2,150.1,108.6z"/>
</g>
</g>
<g id="Layer_14">
<polygon opacity="0.1" points="199.4,200 0,200 0,146.7 200.2,50.6 "/>
</g>
</svg>
Result:
Here is an example https://jsfiddle.net/5w4k5gmy/
I will appreciate your help.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
The Best Way to Embed SVG on HTML (2021) - Vecta.io
Use <img> tag and embed fonts using Nano. If possible use static compression, and compress your SVG with Brotli for the smallest sizes....
Read more >SVG <image> tag inlined in HTML not loading image in browser
This is not the case in question, but I ran across a similar issue with an <image href="/path/to/file. svg"> tag not showing up...
Read more >1. Using SVG in Web Pages - Modern SVG [Book] - O'Reilly
The image will be rendered (“drawn” in the sense that the SVG code is converted to a raster image for display) separately from...
Read more >SVG Images in Power Apps - Matthew Devaney
In this article I'll show you how to use SVG images in Power Apps., where to find SVG icons and how to change...
Read more >drawImage() fails silently when drawing an SVG image ...
The default size of an <img> element is 0x0, so drawing an SVG image ... what to do here: If the image has...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I get the same behaviour
@niklasvh
Hi niklasvh,
I synced the latest version (1.0.0-alpha.12) of html2canvas. But unfortunately, my svg image cannot get rendered in the html canvas, in Chrome browser. In Safari, it works well. What do you think of this issue?
Thank you so much, Kiki
—The below is the image source—
<svg xmlns='http://www.w3.org/2000/svg' version='1.1' baseProfile='full' style='position:absolute; left:0; top:0; width:100%; height:100%; transform:scale(1,-1); transformOrigin:0, 0; z-index:1; ' viewBox='-8302.013422818793 -1000 16604.026845637585 2000' pointer-events='painted'><g><g><g cursor='pointer' pointer-events='paint'><polyline stroke-width='27.027027027026975' stroke='rgba(255,0,0,0.75)' fill='none' points='-1532.43 567.568 -1289.19 -232.432 -1635.14 -124.324 -1159.46 562.162'/></g><g cursor='pointer' pointer-events='paint'><polyline stroke-width='27.027027027026975' stroke='rgba(255,0,0,0.75)' fill='none' points='-175.676 -75.6757 224.324 421.622 683.784 254.054'/><polygon stroke-width='27.027027027026975' stroke='rgba(255,0,0,0.75)' fill='none' points='643.784 254.08 653.159 279.785 683.784 254.054'/></g><circle stroke-width='27.027027027026975' stroke='rgba(255,0,0,0.75)' fill='none' cx='872.9729729729729' cy='129.72972972972974' r='481.08108108108104' cursor='pointer' pointer-events='paint'/><ellipse stroke-width='27.027027027026975' stroke='rgba(255,0,0,0.75)' fill='none' cx='1651.3513513513512' cy='-48.648648648648646' rx='335.1351351351351' ry='248.64864864864865' cursor='pointer' pointer-events='paint'/><rect stroke-width='27.027027027026975' stroke='rgba(255,0,0,0.75)' fill='none' x='1132.4324324324325' y='-594.5945945945946' width='1075.6756756756754' height='1010.8108108108108' cursor='pointer' pointer-events='paint'/><text font-size='108.10810810810813' font-family='Arial' transform='translate(-2954.0540540540537,-16.216216216216225) scale(1,-1)' stroke='rgba(255,0,0,0.75)' fill='rgba(255,0,0,0.75)' cursor='pointer' pointer-events='paint'>KIKI</text></g></g></svg>