Created
July 23, 2014 13:35
-
-
Save simonwoo/d85d5950bc4b874d89ad to your computer and use it in GitHub Desktop.
export raphaeljs svg as an image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* js files to be used | |
* <script src="http://canvg.googlecode.com/svn/trunk/rgbcolor.js"></script> | |
* <script src="http://canvg.googlecode.com/svn/trunk/StackBlur.js"></script> | |
* <script src="http://canvg.googlecode.com/svn/trunk/canvg.js"></script> | |
* <script src="canvas2image.js"></script> | |
* <script src="raphael.export.js"></script> | |
*/ | |
//Convert DOM RaphaelJS element SVG to correct XML (fix images export) | |
var svgText = paper.toSVG(); | |
//add canvas into body | |
var canvasID = "myCanvas"; | |
var canvas = document.createElement('canvas'); | |
canvas.id = canvasID; | |
canvas.setAttribute("style","display:none"); | |
document.body.appendChild(canvas); | |
//convert svg to canvas | |
canvg(document.getElementById(canvasID), svgText, { | |
ignoreMouse: true, ignoreAnimation: true, | |
renderCallback: function () { | |
//save canvas as image | |
Canvas2Image.saveAsPNG(document.getElementById(canvasID)); | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment