Skip to content

Instantly share code, notes, and snippets.

@scottgwald
Last active January 2, 2016 13:49
Show Gist options
  • Select an option

  • Save scottgwald/8313043 to your computer and use it in GitHub Desktop.

Select an option

Save scottgwald/8313043 to your computer and use it in GitHub Desktop.
[wearscript] Two ways to take a photo and show *on canvas*
<html style="width:100%; height:100%; overflow:hidden">
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<canvas id="myCanvas" width="640" height="360"></canvas>
<script>
function photoPath(data) {
WS.say("I got your photo");
var img = new Image();
img.src = data;
img.onload = function() {
context.drawImage(img, 0, 0, canvas.width, canvas.height);
}
}
function photo(data) {
WS.say("I got your camera photo");
var img = new Image();
img.src = 'data:image/jpeg;base64,' + data;
img.onload = function() {
context.drawImage(img, 0, 0, canvas.width, canvas.height);
}
}
function main() {
canvas = document.getElementById('myCanvas');
context = canvas.getContext('2d');
if (WS.scriptVersion(1)) return;
//WS.cameraPhotoPath('photoPath');
WS.cameraPhoto('photo');
}
window.onload = main;
</script>
</body>
</html>
{
"name": "Canvas Photo"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment