Created
December 9, 2020 17:04
-
-
Save corocoto/9124cd27bfea361e780040be1a86045f to your computer and use it in GitHub Desktop.
download canvas image
This file contains hidden or 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
| const canvas = document.querySelector('canvas'); | |
| const downloadLink = document.querySelector('.download-link'); | |
| downloadLink.addEventListener('click', (e) => e.target.href = canvas.toDataURL()); |
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Picture on Canvas</title> | |
| <link rel="stylesheet" href="style.css"> | |
| </head> | |
| <body> | |
| <a href="" download="img.png">Download</a> | |
| <canvas id="canvas" width="550" height="500"></canvas> | |
| <script src="download_canvas.js"></script> | |
| <script src="script.js"></script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment