Created
May 13, 2019 19:31
-
-
Save gladchinda/fed5bb431983297e34b4d81e4097d395 to your computer and use it in GitHub Desktop.
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
img.addEventListener('load', () => { | |
/* ... some code have been truncated here ... */ | |
ctx.putImageData(imageData, 0, 0); | |
// Canvas.toBlob() creates a blob object representing the image contained in the canvas | |
// It takes a callback function as its argument whose first parameter is the | |
canvas.toBlob(blob => { | |
// Create a download link for the blob object | |
// containing the grayscale image | |
const downloadLink = downloadBlob(blob); | |
// Set the title and classnames of the link | |
downloadLink.title = 'Download Grayscale Photo'; | |
downloadLink.classList.add('btn-link', 'download-link'); | |
// Set the visible text content of the download link | |
downloadLink.textContent = 'Download Grayscale'; | |
// Attach the link to the DOM | |
document.body.appendChild(downloadLink); | |
}); | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment