UPDATE: HTML5 Webcam Photobooth Web App
Two days ago I made a little Flash app that will allow anyone to take a picture with a webcam connected to a computer. Everything worked fine in AS3. It was only when I got to the PHP part of the project when I felt like I should ask for help. And I did, I asked a friend or mine (Mihai Bojin) who in a few minutes explained to me exactly what I needed to know in order to get this project working as it should (a big part of the PHP code is made by him).
The project is now open source and you can find the code and the source files underneath 😉
This open source project is release under the MIT license.
You can download the source files from here:
Photo Booth (52.8 KiB, 38,367 hits)
[AdSense-A]Here you can see the working application:
vamapaull.com/photobooth
Here you can see the ActionScript 3.0 code:
import flash.display.Bitmap; import flash.display.BitmapData; import com.adobe.images.JPGEncoder; var snd:Sound = new camerasound(); //new sound instance for the "capture" button click var bandwidth:int = 0; // Maximum amount of bandwidth that the current outgoing video feed can use, in bytes per second. var quality:int = 100; // This value is 0-100 with 1 being the lowest quality. var cam:Camera = Camera.getCamera(); cam.setQuality(bandwidth, quality); cam.setMode(320,240,30,false); // setMode(videoWidth, videoHeight, video fps, favor area) var video:Video = new Video(); video.attachCamera(cam); video.x = 20; video.y = 20; addChild(video); var bitmapData:BitmapData = new BitmapData(video.width,video.height); var bitmap:Bitmap = new Bitmap(bitmapData); bitmap.x = 360; bitmap.y = 20; addChild(bitmap); capture_mc.buttonMode = true; capture_mc.addEventListener(MouseEvent.CLICK,captureImage); function captureImage(e:MouseEvent):void { snd.play(); bitmapData.draw(video); save_mc.buttonMode = true; save_mc.addEventListener(MouseEvent.CLICK, onSaveJPG); save_mc.alpha = 1; } save_mc.alpha = .5; function onSaveJPG(e:Event):void{ var myEncoder:JPGEncoder = new JPGEncoder(100); var byteArray:ByteArray = myEncoder.encode(bitmapData); var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream"); var saveJPG:URLRequest = new URLRequest("save.php"); saveJPG.requestHeaders.push(header); saveJPG.method = URLRequestMethod.POST; saveJPG.data = byteArray; var urlLoader:URLLoader = new URLLoader(); urlLoader.addEventListener(Event.COMPLETE, sendComplete); urlLoader.load(saveJPG); function sendComplete(event:Event):void{ warn.visible = true; addChild(warn); warn.addEventListener(MouseEvent.MOUSE_DOWN, warnDown); warn.buttonMode = true; } } function warnDown(e:MouseEvent):void{ navigateToURL(new URLRequest("images/"), "_blank"); warn.visible = false; } warn.visible = false; |
Here you have the php code:
<?php if(isset($GLOBALS["HTTP_RAW_POST_DATA"])){ $jpg = $GLOBALS["HTTP_RAW_POST_DATA"]; $img = $_GET["img"]; $filename = "images/filename_". mktime(). ".jpg"; file_put_contents($filename, $jpg); } else{ echo "Encoded JPEG information not received."; } ?> |
EDIT 16/03/2010:
From this little experiment a new project called UserBooth came to life 😉
EDIT 04/12/2011:
I just got the approval notice from ActiveDen for a much better version of this PhotoBooth app. This new version includes lot of options to customize it through XML and it includes both ASP and PHP files for the server-side part of the code. If you have any suggestions to improve it, please contact me though my ActiveDen profile
Hi.. thanks for awesome tutorial. great work!!!!
How can I change the resolution 320×240?
grateful
Look at this piece of code:
Yes, I saw this piece of code. But it is inside that file and how do I edit it? much obliged
The FLA file can be opened with Adobe Flash Professional (Google it if you don’t know what that is).
Ok changed this part of the code but now the picture is choppy and continues to 320×240. I would like to capture an image of 90×100
Actually I would like to save an image this size
First I would like to thank for the post, now I need to send to the PHP file photo id and two variables, because it must associate the image to a mysql database.
Already researched quite how to compile the file in flash but unfortunately I know nothing flash.
Its help?
Sorry if the English is incorrect is that I am using google translate.
If you don’t know anything about Flash and ActionScript, I work as a freelancer and you can hire me.
Hi, no questions- I was looking for a way to use the webcam in flash and this really helped, so thanks. I hope this brings you loads of freelance work 🙂
Thank you! I’m glad you like it.
Hi! is there a way where I can add pictures frames and funny stickers to the picture? and other users information like email etc then save it. Thank you
Sure, you can download the source files and modify them however you wish.
Used for a long time with firefox on linux, but now I get the following message:
“The adobe flash player plugin crashed”
this is occurring with firefox 20 and firefox 22 on linux slackware 14 and 14 64 bits
I can’t help you there. Please contact Firefox or Adobe.
this occurs with the plugin is upgraded
I think the most appropriate is the adobe even, as tested with the works and is the same way. Fucnionou with chorme, since chorme comes with your Flash plugin.
Now this is a problem that affects users of your system. It would be interesting Mr. contacting the adobe also
I don’t want to be rude, but I’m not sure I understand your message. Chrome comes with my Flash plugin? And this is a problem that affects users of my system? What system are we talking about?
Dear Vamapaul,
I am trying to integrate the brilliant photobooth app into my php web project for face recognition. I am fairly new to PHP. Could you please tell me, which code in which files need to be chanaged for me to store the images taken for each user. I mean, I am trying to save the images in a folder and using them later for the face recognition functionality. Any help will be much appreciated.
Kindestr egards,
Sav
Did you look at the PHP code posted by me?
Dear Vamapaul,
can you tell me how to capture image by time?
I’m not sure if I understand what you mean by “capture image by time”.
Hey Vamapaull..
when we click on “save image” it shows “image saved successfully.Click here to view gallery”.. how can i prevent this from coming ??
Download the source files, edit the FLA file however you want, then compile a new SWF.
Good evening, I’m in urgent need of help, the flash is in a file in php and I need the swf file (take_picture.swf) take a variable of php file and pass to the save.php file. How could I do this? Looking forward. Thank you.
You first need to pass that variable to the SWF file. Then modify the ActionScript code to send that variable along with the other variables to the save.php file.
is there a way where I can add pictures frames and funny stickers to the picture?
i need tutorial for that
Only if you know your way around ActionScript 3.
Dear Paullstoan,
Thanks for sharing, it is a great work.
Is there any possibility to add face detection option?
Best
Only if you have experience with ActionScript 3 and find a way to make the code for that.
Goodmorning
I was using for mysql it was working fine but when i changed to my sqli its not working.i can see image capture but its not stored in folder.why is this happening.how can i share my code with you.Thanks
Make sure the images folder from your server has 777 permissions.
No its still not working
using wamp sewrver
Goodmorning
Please provide solution as i am using wamp server and windows.permissions are there.
Thanks