Ok you want to waste some time? Good! We cre­ate a script that will cre­ate a pic­ture each 20 min­utes, resize this pic, add a time­stamp to the image. Then we cre­ate a ani­mated gif, so you can watch what hap­pend dur­ing the last week. You need:
–a web­cam (douh!)
–php with gd sup­port
ImageMag­ick
–a tool to grab the image from the web­cam (for exam­ple vgrabbj)

The first step is to cre­ate the image from the web­cam: “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) = getim­a­ge­size($src);
$im = image­cre­ate­frompng($src);
$tim = image­cre­atetrue­color(120, 90);
image­copy­re­sam­pled($tim,$im,0,0,0,0,120,90,$width,$height);
//write cur­rent date and time
$text­color = image­col­oral­lo­cate($tim, 255, 0, 0);
$text­col­orbg = image­col­oral­lo­cate($tim, 0, 0, 0);
$cur­rent­Date  = get­date();
$timeH = $cur­rent­Date[“hours”];
$timeM = $cur­rent­Date[“min­utes”];
$wday = $cur­rent­Date[“wday”];
$day = $cur­rent­Date[“mday”];
$month = $cur­rent­Date[“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, $text­col­orbg);
imagestring($tim, 5, 0, 0, $day/$month $timeH:$timeM, $text­color);
//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
con­vert –adjoin –delay 50 –loop 999 /opt/gif/cam*.gif /opt/animate.gif
ncftp­put –u USER –p PASSWORD YOUR-SERVER /remote/dir/ /local­path/to.png
ncftp­put –u USER –p PASSWORD YOUR-SERVER /remote/dir/ /local­path/to.gif

Now you need to edit crontab, so our Bash script will be exe­cuted each 20 min­utes, 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 exam­ple here.