Created
December 28, 2015 04:44
-
-
Save anehkumar/0f2b1d659b22a1358cb2 to your computer and use it in GitHub Desktop.
This file contains 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
extends layout | |
block content | |
div(class="container" id="Cool" ng-app="mainApp" ng-controller="formController") | |
h2.blue.red#header("property"="pValue") Capture your image from webcam | |
div.row | |
div.col-md-6 | |
video#video(autoplay='') | |
div.col-md-6 | |
canvas#canvas(width='640', height='480') | |
div | |
button#snap Capture | |
button#new New | |
button(id="upload" ng-click="uploadImage()") Upload | |
script(type="text/javascript"). | |
// Put event listeners into place | |
window.addEventListener("DOMContentLoaded", function() { | |
// Grab elements, create settings, etc. | |
var canvas = document.getElementById("canvas"), | |
context = canvas.getContext("2d"), | |
video = document.getElementById("video"), | |
videoObj = { "video": true }, | |
errBack = function(error) { | |
console.log("Video capture error: ", error.code); | |
}; | |
// Put video listeners into place | |
if(navigator.getUserMedia) { // Standard | |
navigator.getUserMedia(videoObj, function(stream) { | |
video.src = stream; | |
video.play(); | |
}, errBack); | |
} else if(navigator.webkitGetUserMedia) { // WebKit-prefixed | |
navigator.webkitGetUserMedia(videoObj, function(stream){ | |
video.src = window.URL.createObjectURL(stream); | |
video.play(); | |
}, errBack); | |
} else if(navigator.mozGetUserMedia) { // WebKit-prefixed | |
navigator.mozGetUserMedia(videoObj, function(stream){ | |
video.src = window.URL.createObjectURL(stream); | |
video.play(); | |
}, errBack); | |
} | |
// Trigger photo take | |
document.getElementById("snap").addEventListener("click", function() { | |
context.drawImage(video, 0, 0, 640, 480); | |
// Littel effects | |
//$('#video').fadeOut('slow'); | |
$('#canvas').fadeIn('slow'); | |
//$('#snap').hide(); | |
//$('#new').show(); | |
// Allso show upload button | |
//$('#upload').show(); | |
}); | |
// Capture New Photo | |
document.getElementById("new").addEventListener("click", function() { | |
//$('#video').fadeIn('slow'); | |
//$('#canvas').fadeOut('slow'); | |
//$('#snap').show(); | |
//$('#new').hide(); | |
}); | |
// Upload image to sever | |
document.getElementById("upload").addEventListener("click", function(){ | |
var dataUrl = canvas.toDataURL(); | |
console.log(dataUrl); | |
}); | |
}, false); | |
var mainApp = angular.module("mainApp", []); | |
mainApp.controller("formController", function($scope, $http) { | |
$scope.uploadImage = function () { | |
var request = $http({ | |
method: "post", | |
url: "/captureImage", | |
data: { | |
base64: document.getElementById("canvas").toDataURL() | |
}, | |
headers: { 'Content-Type': 'application/json' } | |
}); | |
request.success(function (data) { | |
console.log(data); | |
}); | |
request.error(function(serverResponse, status, headers, config) { | |
alert("failure"); | |
}); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment