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
@Matt Yes, it’s doable. I played with this type of stuff in the past and it’s not that hard, but still, you need to have a good understanding of ActionScript 3 and Media Servers to make something worth publishing.
Good luck!
What if I want to add a frame? And also, I can’t figure out where it saves the picture? Any advice? Thanks!
@Arianne Don’t understand the frame part… the images are saved in a folder named “images” you need to make that folder and set permissions to 777
Hello! May i know whether it’s possible to include a comment system where the user can input comments and submit it together with their picture?:)
Sure, it’s possible. You may need some ActionScript skills.
When I try and open the unzipped file I’ve taken from this blog post the .swf file is frozen on the “The image is saved Click here to open the gallery” frame and I cannot interact with it at all. This is the same experience I got when I put the whole folder up on my server to test the file before editing them at all. Am I missing something basic? Sorry for the stupid question!
@David What Flash player are you using ?
@vamapaull: I’m using flash player 10 to test the .swf movie in the folder.
@David Test the files on a server with php support.
Hi vamapaull,
I am comfortable with PHP/MYSQL/XML
I have little knowledge about flash.
I wanted to functionality in take_picture.swf
1.
@jay Don’t know how you answer your question. Heck, don’t even know if you are a bot/spammer.
Hi vamapaull,
I am comfortable with PHP/MYSQL/XML
I have little knowledge about flash.
I wanted to functionality in take_picture.swf
1. I wanted one (Form)Input Box in which one can type number or name or any
alphanumeric characters.When submited this flash along with image, value of this box will will be passed to PHP.
2.Instead of capture & Save functionality seprate,I wanted capture & save functionality in one go.
I wanted tips from you that how can I integrate in existing flash file.
@jay Don’t think I understand exact what you want to achieve. I work as a freelancer, if you need some custom work you can hire me http://www.vamapaull.com/contact
If you are interested, we’ll talk via email and we’ll figure out the details.
Hi,is it possible to use the cam of an Android tablet?
If the SWF file is embedded into a webpage, then I don’t think so.
From what I know the camera is not working in the mobile browser even if the mobile browser has Flash Player.
Hi,
First i just want to thank you for this tutorial… its just perffect man..
I just have a question, in my computer i have a capture board and this software just show the tuner video and i want to see the composite video.. do u understand what i mean?
Thank you
Just right click, then click Settings and click the webcam icon.
Hey,
Great stuff. Just curious as to what flash tool you used to develop this. Flash builder or cs 5?
Thanks.
@Joel I believe the FLA file is saved for CS3
You can open it with CS5 if that’s what you want.
Hi,
Its not working on the server.
permission = 777
any help????
The โimagesโ folder needs to have 777 permission and you need a server with PHP support.
Hi vamapaull
what exactly do you mean by a folder needs to have 777 permission?
Im quite new with PHP.
Thanks
You need to access your server with an FTP client and then go to where you uploaded the files, then right click on the “images” folder, click Properties and then you should see where you can set 777 permissions.
If you still don’t understand, you can try Google “Set 777 Permissions”
Anytime I take pictures on your site the webcam does not freeze but when I take some amount of pictures on my localhost the webcam freezes. Also if I take pictures on my localhost while your capture page is opened its also doesn’t freeze. Can you please help me out.
If the webcam is already in use you can’t open another page with the webcam app and expect to function correctly with that specific webcam.
I see the same thing David above.
I believe the .fla in the archive downloadable from this post is not complete.
The swf in the archive is NOT the same as the one here: http://vamapaull.com/photobooth/take_picture.swf
I understand this post is old, but I wish you guys would clean the info. Where is the open source project? What is being developed, can i buy a copy of userbooth with source from you? Thanks/
Tonight I have some time to spare, and I will take a look at this project and do some updates.
The UserBooth project will soon take another path.
The old UserBooth files are not open source right now and they are not for sale.
If you want a Photo Booth Flash application, try the one I published on ActiveDen. It’s much, much better then this old application and the UserBooth application, and you will get the all source files when you buy it.
Keith, I just checked the source files and everything seems to be the same. The only difference is the graphic interface. But anyone who wants to use this application can make their own graphic interface.
Thanks this is what im looking for
Hello, thank you very much for the source file. Just wondering is there anyway to save as individual jpeg. currently the jpeg is embeded in the index.php. I want the jpgs only in a folder. I know i cant view it on the browser, I just need to jpeg. U get what i mean?
thanks
Currently the application saved the jpg on the server. The jpg files are not embedded into index.php, the php code reads the contents of the folder and displays them.
“I know i cant view it on the browser”
You can’t?
What do you actually want?
Can you try to explain it a little better?
Do you want the application to save the image into your computer instead of saving it on the server?
thank you very much for the source file. Can advice me to insert ‘countdown/animation action before ‘image capture’. thank’s
You can buy the new version if you want the countdown feature.
Hi,
Can this be modified to capture video instead of images only? Would be very interested and even if it means donating something…
Cheers
Capturing video is not that easy.
You need a media server and some ActionScript code made a bit different.
The simple answer to your question is: No.
Hi, thanks for this amazing code. How can i delete the imported bitmaps to star all over again. Thanks in advance
I’m not sure I understand your question.
vamapaull, thanks for your interest! i`ll try to explain better.
Im not AS3 programmer, the photo booth is on frame 2, when i go to frame 1 the photo booth is still active, how can i erase that? i only want the photo booth to work in the second frame.
sorry for my english!
I’m not sure what you are talking about.
This photobooth application has only one frame.
If you need any custom work you can hire me. I work as a freelancer.
Hi, is there anyway to edit the filename after the image has been snapped/saved? And if so could a session be passed to it so only the active user who did the snapshot could rename it?
I believe you could do that with PHP but I’m not a PHP expert.
Okay, is there anyway where I could just have the option of editing the file name before it saving?
Look at the PHP code.
Hi Vamapaul. This is a great release. Just one question. I am planning to use this in a Codeigniter application (based on MVC principle) so I needed to rearrange the files and folders. Is there any way I can specify in the JS/AS code the location of my php processing library?
In the ActionScript code you have this line: var saveJPG:URLRequest = new URLRequest(“save.php”);
Thanks for your response. But I am new to ActionScript. I can see the line you mentioned in the AS code above. But the code is not in any of the downloaded files. How do I use it? Sorry if I’m sounding naive;-)
You need Adobe Flash and you need to open the FLA file.
Search for some tutorials if you want to learn more about Flash and ActionScript.
A good place to start is http://www.gotoandlearn.com
is its possible to save directly in db using session
You have all the source files. You can modify them however you want.