Skip to content

Instantly share code, notes, and snippets.

@corocoto
Created December 9, 2020 17:04
Show Gist options
  • Select an option

  • Save corocoto/9124cd27bfea361e780040be1a86045f to your computer and use it in GitHub Desktop.

Select an option

Save corocoto/9124cd27bfea361e780040be1a86045f to your computer and use it in GitHub Desktop.
download canvas image
const canvas = document.querySelector('canvas');
const downloadLink = document.querySelector('.download-link');
downloadLink.addEventListener('click', (e) => e.target.href = canvas.toDataURL());
<!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