Created
May 29, 2015 15:50
-
-
Save DaveVoyles/a772f9f19a4cd93f6814 to your computer and use it in GitHub Desktop.
savePhoto - GetUserMedia
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
| // savePhoto() - Function invoked when user clicks on the canvas element | |
| // 1. If msSaveBlob is supported, get the photo blob from the canvas and save the image file | |
| // 2. Otherwise, set up the download attribute of the anchor element and download the image file | |
| var savePhoto = function() { | |
| if (photoReady) { | |
| var canvas = document.getElementById('canvasTag'); | |
| if (navigator.msSaveBlob) { | |
| var imgData = canvas.msToBlob('image/jpeg'); | |
| navigator.msSaveBlob(imgData, 'myPhoto.jpg'); | |
| } | |
| else { | |
| var imgData = canvas.toDataURL('image/jpeg'); | |
| var link = document.getElementById('saveImg'); | |
| link.href = imgData; | |
| link.download = 'myPhoto.jpg'; | |
| link.click(); | |
| } | |
| canvas.removeEventListener('click', savePhoto); | |
| document.getElementById('photoViewText').innerHTML = ''; | |
| photoReady = false; | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment