PHP script to grab, proxy, resample and combine from mjpeg streams
  Introduction 
This script has 2 clearly seperated functions and is easy to figure out. It will proxy and grab a single image from a mjpeg stream and it grabs and resizes 4 pictures and fits them in an empty image of the original size using PHP with GD. Not the most efficient but it works, the grabber and resize portions can be easily seperated.
  Installation 
Make sure you have a current version of PHP installed and enabled. You will also need GD with the PEAR canvas module
  Code 
<?php
  // ***************
  // * Jim Anthony *
  // ***************
  function get_image($port)
  {
    $packetsize = 2048;
    $handle = fopen("http://127.0.0.1:$port/", "rb");
    $response = fread($handle, 75);
    $jpglength = substr($response, 65);
    $packets = floor($jpglength / $packetsize);
    for ($i = 0, $jpgfile = ''; $i < $packets; $i++)
      $jpgfile .= fread($handle, $packetsize);
    $jpgfile .= fread($handle, $jpglength % $packetsize);   
    fclose($handle);
    $image = imagecreatefromstring($jpgfile);
    return($image);
  }
  $image = imagecreatetruecolor(640, 480);
  imagecopyresampled($image, get_image(8001), 0, 0, 0, 0, 320, 240, 640, 480);
  imagecopyresampled($image, get_image(8002), 320, 0, 0, 0, 320, 240, 640, 480);
  imagecopyresampled($image, get_image(8003), 0, 240, 0, 0, 320, 240, 640, 480);
  imagecopyresampled($image, get_image(8004), 320, 240, 0, 0, 320, 240, 640, 480);
  header("Content-type: image/jpeg");
  imagejpeg($image);
  destroy($image);
?>
Based on John Huongs script
  
Fatal error: Call to undefined function imagecreatetruecolor() in /var/www/fusetech/live.php on line 20
-- 
RomanGaufman - 23 Jul 2008