Skip to content

Instantly share code, notes, and snippets.

@DaveVoyles
Created May 29, 2015 15:50
Show Gist options
  • Select an option

  • Save DaveVoyles/a772f9f19a4cd93f6814 to your computer and use it in GitHub Desktop.

Select an option

Save DaveVoyles/a772f9f19a4cd93f6814 to your computer and use it in GitHub Desktop.
savePhoto - GetUserMedia
// 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