Colin McKinnon <Colin McKinnon <co**************@andthis.mms3.com>> wrote:
Anybody tried this? Know of any published work on the topic? More
specifically, I am have a webcam (hardware device which connects directly
to the network) which will be behind a public webserver (LAMP). The
webserver will serve up predominantly static content. I want it to mediate
access to the camera for security reasons (camera control is exposed via
HTTP, also provides different URLs for different protocols / resolutions)
to manage bandwidth more cleverly.
I hope I got this right: The webcam capture is an image, obtainable through
HTTP? If so, you could grab the image using file_get_contents() and then
open and resize it using the gd library <http://www.php.net/gd>. Either on
demand on the server or invoked as a cronjob every x minutes.
I understand "different protocols" as "HTTP, FTP, maybe some more", so you
would need the image as file(s) on the hard disk. Since you can't check for
requests to the image via FTP (as long as you don't use special software) I
would suggest using the cronjob and a command line script (untested!):
(You need PHP as binary to do so!)
<?php
set_time_limit(0); // could take some time ;)
// getting the original image
$image = file_get_contents('http://webcamserver/path/to/webcamshot.jpg');
fwrite($f = fopen('original.jpg', 'w'), $image);
fclose($f); unset($image);
// the width of the resized images
// (height will be calculated)
$resolutions = array(
400,
320,
240,
160,
80 // no comma here!
);
// opening the original image
$orig = ImageCreateFromJPEG('original.jpg');
$ow = ImageSX($orig);
$oh = ImageSY($orig);
$ratio= ((float) $oh) / ((float) $ow);
$path = 'path/to/public/images/';
foreach ($resolutions as $w) {
$h = round($ratio * $w);
$im = ImageCreateTrueColor($w, $h);
ImageCopyResampled($im, $dest, 0, 0, 0, 0, $w, $h, $ow, $oh);
ImageJPEG($im,$path.$w.'.jpeg',80);
ImageDestroy($im);
}
?>
--
Simon Stienen <http://dangerouscat.net> <http://slashlife.de>
»What you do in this world is a matter of no consequence,
The question is, what can you make people believe that you have done.«
-- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle