Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. <a id="downloadLnk" download="your-drawing.png" href="javascript:void(0)"><img src="images/save.png" height="30px" width="30px" /></a>
  2.  
  3. <script language="javascript">
  4. function download() {
  5. // get the canvas 2d context
  6. var ctx = canvas.getContext('2d');
  7. // set the ctx to draw beneath your current content
  8. ctx.globalCompositeOperation = 'destination-over';
  9. // set the fill color to white
  10. ctx.fillStyle = 'white';
  11. // apply fill starting from point (0,0) to point (canvas.width,canvas.height)
  12. // these two points are the top left and the bottom right of the canvas
  13. ctx.fillRect(0, 0, canvas.width, canvas.height);
  14. var dt = canvas.toDataURL('image/png');
  15. this.href = dt;
  16. };
  17.  
  18. downloadLnk.addEventListener('click', download, false);
  19.  
  20. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement