Pi Photo Booth
Pi Photo Booth
To follow along with this tutorial you would need to have a Raspberry Pi with the
Apache Server & PHP installed. View my previous tutorial for details on how to install
Apache & PHP on the Raspberry Pi. (https://youtu.be/Ak1zqqnfsc8) You will also
need a camera module which you can purchase here http://amzn.to/20zDytT
Keep in mind, the camera modules are sensitive. Be sure to where rubber sole shoes
while handling them.
I have a Adafruit touch screen for my project, but that’s not necessary and frankly, if
you are not good at tinkering, I would recommend against using this screen.
http://amzn.to/1R54rna
If you want to access camera module via php you will first need to run this line in
command…
sudo chmod 0777 /dev/vchiq
and add same chmod to directory where you need to save photos. Otherwise, you will
not be able to save to that directory.For example: chmod 0777 /var/www/cam
sudo chmod -R 0777 /var/www/slide
test camera by running this code
sudo raspistill -o image.jpg -w 640 -h 480 2>&1
the camera preview should popup on the screen and after a few seconds a pic should be taken and
stored in the current directory with the name image.jpg
If you are using a piTFT, as I am, you will want to use the following command to put
the screen into frame buffer mode: fbcp &
To kill this process use this command: killall fbcp
You may need to add FBCP before running the above command. Instruction can be
found here: https://github.com/notro/fbtft/wiki/Framebuffer-use
A homepage that has a two links. One to the camera page which triggers the raspberry
pi to take a photo and one to the gallery page which displays all the previous photos
taken.
The exec call is great php call. This allows you run any terminal command from web
browser.
index.php
has a link to the camera.php page and gallery.php page
<a href="camera.php">Take A photo</a><a href="gallery.php">Take A photo</a>
camera.php
$command= 'raspistill --nopreview -o /var/www/cam/image.jpg -w 640 -h 480 2>&1 ';
$escaped_command = escapeshellcmd($command);
exec($command, $test, $retval);
I created a random name generator and used that for my image file name. This way the
different image name is created each time I call this script
$length = 6; $characters =
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength =
strlen($characters); $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .=
$characters[rand(0, $charactersLength - 1)]; }
$command= 'raspistill -o /var/www/cam/'.$randomString.'.jpg -w 640 -h 480 2>&1 ';
//DISPLAY the image you just took.
echo '<p>'.implode ( '</p><p>' , $test ).'</p>'; //if there is an error
$myRand=rand(0, 1000);
echo "<img src='$randomString.jpg?n=$myRand'/>";//the myRand make sure current image is shown
and not cached image
IMAGE gallery.php
displays the images in thumbnail form and allows mouse click to show selected image.
First image in gallery is displayed as large image at top of page