Ok you want to waste some time? Good! We create a script that will create a picture each 20 minutes, resize this pic, add a timestamp to the image. Then we create a animated gif, so you can watch what happend during the last week. You need:
–a webcam (douh!)
–php with gd support
–ImageMagick
–a tool to grab the image from the webcam (for example vgrabbj)
The first step is to create the image from the webcam: “vgrabbj –o png –f /opt/cam.png”
Now we start with the PHP script (/opt/resize.php), that will resize the image and add the timestamp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <?php $src = “/opt/cam.png”; $dst = “/opt/camRes.png”; //resize list($width, $height, $type, $attr) = getimagesize($src); $im = imagecreatefrompng($src); $tim = imagecreatetruecolor(120, 90); imagecopyresampled($tim,$im,0,0,0,0,120,90,$width,$height); //write current date and time $textcolor = imagecolorallocate($tim, 255, 0, 0); $textcolorbg = imagecolorallocate($tim, 0, 0, 0); $currentDate = getdate(); $timeH = $currentDate[“hours”]; $timeM = $currentDate[“minutes”]; $wday = $currentDate[“wday”]; $day = $currentDate[“mday”]; $month = $currentDate[“mon”]; if ($day < 10) $day = “0$day”; if ($month < 10) $month = “0$month”; if ($timeH < 10) $timeH = “0$timeH”; if ($timeM < 10) $timeM = “0$timeM”; imagestring($tim, 5, 1, 1, “$day/$month $timeH:$timeM”, $textcolorbg); imagestring($tim, 5, 0, 0, “$day/$month $timeH:$timeM”, $textcolor); //save imagepng($tim, $dst); imagegif($tim, “/opt/gif/cam$wday-$timeH-$timeM.gif”); ?> |
Now the Bash script (/opt/doimg.sh). This script will do the rest (get the image, process it and upload it with ncftp):
1 2 3 4 5 6 | #!/bin/sh vgrabbj –o png –f /opt/cam.png php /opt/resize.php convert –adjoin –delay 50 –loop 999 /opt/gif/cam*.gif /opt/animate.gif ncftpput –u USER –p PASSWORD YOUR-SERVER /remote/dir/ /localpath/to.png ncftpput –u USER –p PASSWORD YOUR-SERVER /remote/dir/ /localpath/to.gif |
Now you need to edit crontab, so our Bash script will be executed each 20 minutes, edit /etc/crontab and add those lines:
1 2 3 | 00 * * * * root /opt/doimg.sh 20 * * * * root /opt/doimg.sh 40 * * * * root /opt/doimg.sh |
You can take a look at the example here.

One Comment
1 kpos wrote:
In cron you can use: */20 in the first line, and will work every 20 minutes as well. Just simpler :)