PDA

View Full Version : HTML5 Canvas javascript svg to jpg/png


ibrahimjan2005428730
07-27-2011, 03:09 PM
Hi All

I need a bit of help in javascript, I am using the google canvg script to create canvas from SVG file, that works all fine I get the SVG file converted to canvas.

What I need to do now is convert the canvas to a jpg or png, using the toDataURL function in html5, please have a look at the script and see how we can get this to work, my knowledge in java scripting is not very strong please excuse my ignorance:



<script type="text/javascript" src="/js/rgbcolor.js"></script>
<script type="text/javascript" src="/js/canvg-1.0.js"></script>


<canvas id="canvas" width="0px" height="0px"></canvas>

<script type="text/javascript">
window.onload = function() {
var canvas = canvg('canvas', '../gallery/svg/myfile45.svg');
window.location = canvas.toDataURL("image/png");
}
</script>


Live script http://www.jancodesign.com/svg_canvas.asp


Thank you,