Fake Webcam

fake webcam

My live webcam isn't really live and isn't really a webcam. It's a perl script that I wrote that draws a picture that simulates a live webcam.

The script takes a few images and composites them together:

The script chooses a background based on the time and randomly positions the head on it. The script also displays a message and date/time stamp to give the image more authenticity.


#!/usr/bin/perl -w
#
# fake-webcam.cgi
#
# Author:      Steve DeGraeve
# created:     Feb 07 2005
# modified:    Feb 07 2005
# description: 
#              This script makes a fake webcam image with an 
#              up-to-date date time stamp on it.
#              Fool your friends.  Fun at parties.
#
######################################################################

use Image::Magick;


print "Content-type: image/jpeg\n\n";

my($image, $x, $im);

# what time is it?  I don't know.  I don't have my watchimal on.
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

# create a new fake webcam image
# get background image and head
$room = Image::Magick->new;
$head = Image::Magick->new;
if ($hour > 18) {
    $room->Read('webcamroomday.jpg');
    $head->Read('webcamheadday.png');
} else {
    $room->Read('webcamroomnight.jpg');
    $head->Read('webcamheadnight.png');
}

# copy my head onto background
$randx = rand(110) + 30;
$randy = rand(40) + 30;

$room->Composite(image=>$head,compose=>'Atop', x=>$randx, y=>$randy);

# draw the black box at the bottom of the im for the mesg
$room->Draw(fill=>'black', primitive=>'rectangle', points=>'1,225 320,240 ');

# get a funny mesg to show on the bottom of the fake webcam image
open (FILE, 'webcamtext.txt');
@LINES=<FILE>;
close(FILE);
$SIZE=@LINES;

$yday++;
if ($yday > $SIZE){
    $mesg = $LINES[$yday % $SIZE];	
} else {
    $mesg = $LINES[$yday];	
}
chop $mesg;

# write the mesg and date/time to the fake webcam img
if ($min < 10) {$min = "0".$min;};
$mesg .= " :: " . ($mon+1) . "/" . $mday . "/" . ($year+1900) . " @ " . $hour . ":" . $min;
$room->Annotate(font=>'verdana.ttf', pointsize=>9, fill=>'white', text=>$mesg, y=>236, x=>5, antialias=>'false');

# make sure we are writing to a binary stream
binmode STDOUT;


# Convert the image to JPEG and print it on standard output
$room->Write('jpg:-');