Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-12-2012, 10:17 AM   PM User | #1
fh204
New to the CF scene

 
Join Date: Nov 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
fh204 is an unknown quantity at this point
Need help to create a photobooth

Hi I have a question about Javascript. I want to make my own photobooth, I have found this article how to make one:
http://arstechnica.com/business/2012...ew-webcam-api/

I want to add some to it, I want to put a image file (glasses, hat, mustache) over the webcam canvas and take a picture. The result I want is a snapshot with the image file in it.

I did found some code that would be helpful but it didn't work out for me.

var ctx = bril.getContext("2d");
var img=new Image();
img.onload=function()
{
ctx.drawImage(img,0,0); // img of canvas
};
img.src='IMAGE.png';

Is this possible? Thank you!
fh204 is offline   Reply With Quote
Old 11-12-2012, 10:50 PM   PM User | #2
Brandnew
New Coder

 
Join Date: Aug 2012
Posts: 50
Thanks: 0
Thanked 11 Times in 11 Posts
Brandnew is an unknown quantity at this point
Why don't you add in the code that you're trying to make work with this canvas...

the way i've been learning HTML5 and how to call the image onto the canvas would follow:
Code:
var img;
function eventWindowLoaded(){
img = new Image();
img.src = "IMAGE.png";
img.onload = eventLoaded;
}
and then for the canvas:

Code:
<script type="text/javascript">
var bril = document.getElementById("canvas");
var ctx = bril.getContext("2d");
</script>
<body>
<div style="position: absolute; top:50px; left:50px;">
<canvas id="canvas" width="320" height="250" >Does not Support Canvas</canvas>
</div>
</body>
__________________
1 Corinthians 15:3-4 / Ephesians 2:8-9 - What or Who are you living for?
Brandnew is offline   Reply With Quote
Old 11-12-2012, 10:51 PM   PM User | #3
Brandnew
New Coder

 
Join Date: Aug 2012
Posts: 50
Thanks: 0
Thanked 11 Times in 11 Posts
Brandnew is an unknown quantity at this point
of course there is a little more to the coding but i'm just putting this in terms of the format...
__________________
1 Corinthians 15:3-4 / Ephesians 2:8-9 - What or Who are you living for?
Brandnew is offline   Reply With Quote
Old 12-06-2012, 02:13 PM   PM User | #4
fh204
New to the CF scene

 
Join Date: Nov 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
fh204 is an unknown quantity at this point
Quote:
Originally Posted by Brandnew View Post
Why don't you add in the code that you're trying to make work with this canvas...

the way i've been learning HTML5 and how to call the image onto the canvas would follow:
Code:
var img;
function eventWindowLoaded(){
img = new Image();
img.src = "IMAGE.png";
img.onload = eventLoaded;
}
and then for the canvas:

Code:
<script type="text/javascript">
var bril = document.getElementById("canvas");
var ctx = bril.getContext("2d");
</script>
<body>
<div style="position: absolute; top:50px; left:50px;">
<canvas id="canvas" width="320" height="250" >Does not Support Canvas</canvas>
</div>
</body>
Thank you I have given a try but I didn't managed to pull it off. I have added a image how the photo should looks like if it's finished and the code what I now have at the moment. I can take a picture with the webcam and I can drag a png image over the canvas but when I take a picture the png image isn't on the photo. Is there a way to fix this. Many thanks.

<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
</head>
<body>

<video id="live" autoplay></video>
<div id="draggable" class="ui-widget-content">
<p><img src="images/h.png" width="347" height="347" id="draggable"></p>
</div>

<canvas id="foto" style="display:none"></canvas>
<p><a href="#" onClick="takepicture()">Take picture</a></p>

<div id="filmroll"></div>

<script type="text/javascript">
video = document.getElementById("live")
navigator.webkitGetUserMedia(
{video: true, audio: true},
function(stream) {
video.src = window.webkitURL.createObjectURL(stream)
},
function(err) {
console.log("Unable to get video stream!")
}
)

function takepicture() {
live = document.getElementById("live")
photo = document.getElementById("photo")
filmroll = document.getElementById("filmroll")

photo.width = live.clientWidth
photo.height = live.clientHeight

var photo = document.getElementById("canvas");
var ctx = foto.getContext("2d");

var img;
function eventWindowLoaded(){
img = new Image();
img.src = "images/h.png";
img.onload = function(){
ctx.drawImage(img,0,0);
}
}

img = document.createElement("img")
img.src = foto.toDataURL("image/png")
img.style.padding = 5
img.width = foto.width / 2
img.height = foto.height / 2

filmroll.appendChild(img)
}

$(function() {
$( "#draggable" ).draggable();
});
</script>

<div style="position: absolute; top:50px; left:50px;">
<canvas id="canvas" width="320" height="250" >Does not Support Canvas</canvas>
</div>

</body>
</html>
Attached Thumbnails
Click image for larger version

Name:	example.jpg
Views:	14
Size:	23.7 KB
ID:	11760  

Last edited by fh204; 12-07-2012 at 10:32 AM..
fh204 is offline   Reply With Quote
Old 12-06-2012, 02:51 PM   PM User | #5
fh204
New to the CF scene

 
Join Date: Nov 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
fh204 is an unknown quantity at this point
Quote:
Originally Posted by Brandnew View Post
Why don't you add in the code that you're trying to make work with this canvas...

the way i've been learning HTML5 and how to call the image onto the canvas would follow:
Code:
var img;
function eventWindowLoaded(){
img = new Image();
img.src = "IMAGE.png";
img.onload = eventLoaded;
}
and then for the canvas:

Code:
<script type="text/javascript">
var bril = document.getElementById("canvas");
var ctx = bril.getContext("2d");
</script>
<body>
<div style="position: absolute; top:50px; left:50px;">
<canvas id="canvas" width="320" height="250" >Does not Support Canvas</canvas>
</div>
</body>
I have given multiple tries but I didn't managed to get it done. I have added a example picture how it should looks like if it's finished, and I added the code I have at the moment.
About the code, I can take pictures with the webcam and I can drag a png image over the canvas using the javascript draggable feature. But when I take a picture the png image isn't on the picture. Is it possible to fix this. Many thanks.

<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>

</head>
<body>

<video id="live" autoplay></video>
<div id="draggable" class="ui-widget-content">
<p><img src="image.png" width="347" height="347" id="draggable"></p>
</div>

<canvas id="photo" style="display:none"></canvas>
<p><a href="#" onClick="takephoto()">take picture</a></p>

<div id="filmroll"></div>

<script type="text/javascript">
video = document.getElementById("live")
navigator.webkitGetUserMedia(
{video: true, audio: true},
function(stream) {
video.src = window.webkitURL.createObjectURL(stream)
},
function(err) {
console.log("Unable to get video stream!")
}
)

function takephoto() {
live = document.getElementById("live")
photo = document.getElementById("photo")
filmroll = document.getElementById("filmroll")

photo.width = live.clientWidth
photo.height = live.clientHeight

var photo = document.getElementById("canvas");
var ctx = photo.getContext("2d");

var img;
function eventWindowLoaded(){
img = new Image();
img.src = "image.png";
img.onload = function(){
ctx.drawImage(img,0,0);
}
}

img = document.createElement("img")
img.src = photo.toDataURL("image/png")
img.style.padding = 5
img.width = photo.width / 2
img.height = photo.height / 2

filmroll.appendChild(img)
}
//http://docs.jquery.com/UI/Draggable
$(function() {
$( "#draggable" ).draggable();
});
</script>

</body>
</html>
Attached Thumbnails
Click image for larger version

Name:	example.jpg
Views:	12
Size:	23.7 KB
ID:	11769  

Last edited by fh204; 12-07-2012 at 03:13 PM..
fh204 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:27 AM.


Advertisement
Log in to turn off these ads.