0% found this document useful (0 votes)
149 views3 pages

Pi Photo Booth

This document provides instructions for setting up a Raspberry Pi photo booth using a camera module, PHP, and a touch screen. Key steps include: 1. Installing Apache and PHP on the Raspberry Pi and connecting a camera module. 2. Configuring permissions and testing the camera via the command line. 3. Creating three PHP pages - an index page with links to trigger photos and view galleries, a camera page to capture photos, and a gallery page to view thumbnails and full-size images. 4. Using PHP commands to capture photos from the camera module and display them.

Uploaded by

Cesar Escobar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
149 views3 pages

Pi Photo Booth

This document provides instructions for setting up a Raspberry Pi photo booth using a camera module, PHP, and a touch screen. Key steps include: 1. Installing Apache and PHP on the Raspberry Pi and connecting a camera module. 2. Configuring permissions and testing the camera via the command line. 3. Creating three PHP pages - an index page with links to trigger photos and view galleries, a camera page to capture photos, and a gallery page to view thumbnails and full-size images. 4. Using PHP commands to capture photos from the camera module and display them.

Uploaded by

Cesar Escobar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Raspberry 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

USING CAMERA MODULE VIA WEB

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

Launch browser remotely


sudo DISPLAY=:0 chromium http://localhost
3 PHP pages needed to make this work.

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

<html> <head> <script>


function changeImg(spot) {
document.getElementById("photo").innerHTML="<img src="+spot+" width=600
height=400 >";
}
</script>
</head>
<body>
<?
$fig=dirname(__FILE__);
$dir = $fig; $imagem="n"; $fname=$_GET["filer"]; $del=$_GET["del"]; if($del=="yes"){
//echo"detelte a file<br>";
deleteFile($fname);
}
$dh = opendir($dir);
$fileimg=null; //echo "F: $dir"; $count=0; echo"<table width=\"350\"><tr>";
while (($file = readdir($dh)) !== false) { $str= strlen($file);
if($str>4){ $str=$str-3; $rest =
substr($file, $str,3); if($rest=="jpg"){ if($count==0){
echo' <div id="photo"> <img src= "'; echo "$file"; echo '"
width="600" height="400" alt="previous" title="My Image" border="0"> </div>';
} $count++; echo"<td><a href=\"#\"
onClick=\"changeImg('$file')\"><img src=\"$file\" width=\"214\" height=\"150\"
/></a> <br>$count : <a href=\"gal.php?del=yes&filer=$file\">delete</a> </td>" ;
if($count%3==0){ echo"</tr><tr>";
} }//this is a jpg image }//this
is a file of length greater then 4 }//end of while loop echo"</tr></table>";
function deleteFile($fn) { echo "$fn deleted.<br>"; unlink($fn); }
closedir($dh3); ?> </body> </html>

You might also like