<?php

function savePhoto($remoteImage, $isbn) {
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $remoteImage);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 2);
    $fileContents = curl_exec($ch);
    curl_close($ch);
    $newImg = imagecreatefromstring($fileContents);
    return imagejpeg($newImg, "./{$isbn}.jpg",100);
}

function grab_image($url,$saveto){
    $ch = curl_init ($url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
    $raw=curl_exec($ch);
    curl_close ($ch);
    if(file_exists($saveto)){
        unlink($saveto);
    }
    $fp = fopen($saveto,'x');
    fwrite($fp, $raw);
    fclose($fp);
}

//savePhoto('http://none@192.168.1.21/IMAGE.JPG', 'snapshot2');
//savePhoto('http://192.168.1.25/snapshot.cgi', 'snapshot2');

////savePhoto('http://192.168.1.22/img/snapshot.cgi?size=3&quality=1', 'snapshot3');
//shell_exec('/usr/bin/streamer -q -c /dev/video -j 100 -o snapshot3.jpeg 2>&1 1> /dev/null');


//savePhoto('http://192.168.1.20/img/snapshot.cgi?size=3&quality=1', 'snapshot');
////savePhoto('http://192.168.1.23/img/snapshot.cgi?size=3&quality=1', 'snapshot4');
//savePhoto('http://192.168.1.24/image.jpg', 'snapshot5');
//savePhoto('http://none@192.168.1.26/snapshot.cgi', 'snapshot6');
//savePhoto('http://none@192.168.1.27/snapshot.cgi', 'snapshot6');
//savePhoto('http://none@192.168.1.25/snapshot.cgi', 'snapshot7');
//grab_image('http://192.168.1.87/images/webcam.jpg', 'snapshot8.jpg');
//savePhoto('http://rpi-newcam.wm.internal/cam/webcam.jpg', 'snapshot8');
//savePhoto('http://rpi2-wifi.wm.internal/cam/rpi.jpg', 'snapshot9');
//savePhoto('http://rpi.wm.internal/cam/rpi.jpg', 'rpi');
//savePhoto('http://ebb-rpi/picture/1/current/?_username=admin&_signature=f89dea33fcdeba41f138480eb8fc29be156b54af', 'snapshot9');
?> 
<meta http-equiv="refresh" content="60">
<!--<table>
  <tr>
    <td>
      <img src=snapshot8.jpg>
    </td>
    <td>
      <img src=snapshot3.jpg>
    </td>
  </tr>
  <tr>
    <td>
	  <img src=snapshot4.jpg>
    </td>
    <td>
    </td>
  </tr>
</table>-->
<img src=rpi.jpg?<?php echo filemtime('rpi.jpg')?>>
<!--<img src=snapshot8.jpg

> -->

      
