<?php
/*
My Super Duper Webcam Interface.
wrote it once, lost it, wrote it again.
So, this is version 2.0
What it does?
Sucks a jpeg from stdout that was spewed
by clcam. (see: sourceforge for the project)
sticks a caption on it, saves it in a cache dir.
When the camera is "busy" it spews a previously
cached image.
It all currently works with php4 point anything
GD is required, and a ttf font file of your choice.
But, really, lets face it I'm not gonna dress it up
all pretty. We're not going to the prom.
So, use it if you want. It's fairly straight forward.
code at darryl clarke \. com
*/
// some variables - if you use a jpg here change the line
// where $defaultimg is used to say 'jpeg' instead of 'png'
// default image shows up if new images aren't avail
// and the last cached is a few hours old
$defaultimg = "/home/dclarke/public_html/offline.png";
// open the door, let the girl in
$pipe = popen("clcam -q 75 -o - -t JPG", "r");
if ($pipe) {
// check her out
while(!feof($pipe)) {
$image .= fread($pipe,1024);
}
if ($image == "") {
// you've seen her before, you know what to do
$cache = TRUE;
// ** This directory MUST be webserver read/writable!
$cachedir = "/home/dclarke/public_html/webcam/";
$file = `ls -tr $cachedir | tail -2`;
// we want the 2nd last file written
// the first is the newest which will throw
// an error because.. it's being written!
list($file, $file2) = explode("\n", $file);
list($time) = explode(".", $file);
if ((date("U") - $time) < 3600) {
$img = @imagecreatefromjpeg($cachedir . $file) or
// change this to jpeg if you're using a jpeg as default
$img = @imagecreatefrompng($defaultimg);
}
else {
// last cached image is old, display 'offline'
//default offline image
$img = @imagecreatefrompng($defaultimg);
}
}
else {
// she's new, lets tag her.
$img = @imagecreatefromstring($image);
}
}
if (!$cache) {
// dress up the font settings
$font = "/home/dclarke/public_html/hand.ttf";
$caption = "pileofcrap.org @\r\n" . date("l \\t\h\e jS \o\f F \a\\t g:i a");
$fontsize = "12";
// set the mood lighting
$black = imagecolorallocate($img,5,5,5);
$white = imagecolorallocate($img,255,255,255);
// get funky
// with the cheap $2 hooker and an offset shadow
imagettftext($img, $fontsize, 0, 9,204, - $black, $font, $caption);
imagettftext($img, $fontsize, 0, 11,206, - $black, $font, $caption);
imagettftext($img, $fontsize, 0, 10,205, - $white, $font, $caption);
// timestamp for age
$file = date("U") . ".jpg";
imagejpeg($img, "/home/dclarke/public_html/webcam/" . $file);
}
// finish it off
header("content-type: image/jpg");
imagejpeg($img);
// clean up the mess
imagedestroy($img);
?>

