Skip to content

Instantly share code, notes, and snippets.

@thekhairul
Last active September 9, 2021 16:13
Show Gist options
  • Save thekhairul/cbd972c6267cb9b432a42f553744ef4b to your computer and use it in GitHub Desktop.
Save thekhairul/cbd972c6267cb9b432a42f553744ef4b to your computer and use it in GitHub Desktop.
Download image from browser canvas API
canvas.toBlob((blob) => {
const anchor = document.createElement('a');
anchor.download = 'my-file-name.jpeg'; // optional, but you can give the file a name
anchor.href = URL.createObjectURL(blob);
anchor.click(); // ✨ magic!
URL.revokeObjectURL(anchor.href); // remove it from memory and save on memory!
}, 'image/jpeg', 0.9);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment