Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <a id="downloadLnk" download="your-drawing.png" href="javascript:void(0)"><img src="images/save.png" height="30px" width="30px" /></a>
- <script language="javascript">
- function download() {
- // get the canvas 2d context
- var ctx = canvas.getContext('2d');
- // set the ctx to draw beneath your current content
- ctx.globalCompositeOperation = 'destination-over';
- // set the fill color to white
- ctx.fillStyle = 'white';
- // apply fill starting from point (0,0) to point (canvas.width,canvas.height)
- // these two points are the top left and the bottom right of the canvas
- ctx.fillRect(0, 0, canvas.width, canvas.height);
- var dt = canvas.toDataURL('image/png');
- this.href = dt;
- };
- downloadLnk.addEventListener('click', download, false);
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement