#!/usr/bin/perl

#
#
# (c) 1998 Marcus Porter
#
# fishcam CGI Push Animation
#

# location of snapshot
$snapfile = "/insert/path/to/your/file/current.jpg";

# the delay time between each frame
$delaytime = 30;

# response header stuff
$httpok = "HTTP/1.0 200"; 
$type = "Content-type:";
$length = "Content-length:";
$boundary = "foobarlishous";
$typemixed = "$type multipart/x-mixed-replace;boundary=$boundary";
$typegif = "$type image/gif";
$typejpg = "$type image/jpeg";
$typetxt = "$type text/plain";

$| = 1; # force a flush after each print

# send the main http header
print "$httpok\n";
print "$typemixed\n\n";
# inside boundaries have a leading '--'  
print "\n--$boundary\n";

# main loop
while (1==1)     # do forever.  CGI is interupted when user quits
  {
  $size = -s $snapfile;  #find size of picture


  # the content-length header may be required by HTTP 1.1, 
  # it's optional in HTTP 1.0, but some browsers will 
  # use it to display progress to the user if you send it.
  print "$length $size\n";
  print "$typejpg\n\n";

  # now send the JPEG, keeping it open for a minimum
  # amount of time.
  open (INFILE, "<$snapfile");
  sysread(INFILE, $buffer, $size);
  close(INFILE);
  syswrite(STDOUT, $buffer, $size);
  

# inside boundaries have a leading '--'  
print "\n--$boundary\n";
sleep $delaytime;

}