its all about you, its all about me, its what they said we could be
[quickshow.git] / show.php
index 701a301..5d70a62 100644 (file)
--- a/show.php
+++ b/show.php
@@ -5,15 +5,20 @@
  * of them along with clickable links to see the full thing
  */
 
-#$show_dir = "/export/data/Pictures/showdir";
-$show_dir = "/home/paulr/lithium/data/Pictures/show";
-$n_per_line = 4;
-$this_url = "http://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
+// set these variables
+$n_per_line = 6; // number of pics in each line of the table
+$thumb_size = 300; // size of thumbnails
+$med_size = 1024; // size of "medium" image
+
+
+$show_dir = "/net/iron/export/quickshow/";
+$this_url = "http://".$_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"];
+
 
 
 if(isset($_REQUEST["showpic"])) {
        // show the pic requested...
-       if(preg_match("/.*\\+.*/", $_REQUEST["showpic"])) {
+       if(preg_match("/.*\/+.*/", $_REQUEST["showpic"])) {
                header("Status: 403 i dont think so");
                error_log("throwing 403");
                return;
@@ -26,9 +31,84 @@ if(isset($_REQUEST["showpic"])) {
        } else {
                header("Status: 404 Not Found");
        }
+} else if(isset($_REQUEST["fullpic"])) {
+       $file = $_REQUEST["fullpic"];
+       if(preg_match("/.*\/+.*/", $_REQUEST["fullpic"])) {
+               error_log("throwing 403");
+               header("Status: 403 i dont think so");
+               return;
+       }
+       $afile = "$show_dir/".$_REQUEST["fullpic"];
+       if(file_exists($afile)) {
+               echo "<html><body><h1>Fullsize picture $file</h1><a href=\"$this_url\"><img width=\"100%\" src=\"$this_url?showpic=$file\"></body></html>";
+       } else {
+               header("Status: 403 i dont think so");
+               return;
+       }
+       return;
+} else if(isset($_REQUEST["medpic"])) {
+       $file = $_REQUEST["medpic"];
+       if(preg_match("/.*\/+.*/", $_REQUEST["medpic"])) {
+               error_log("throwing 403");
+               header("Status: 403 i dont think so");
+               return;
+       }
+       $afile = "$show_dir/".$_REQUEST["medpic"];
+       if(file_exists($afile)) {
+               echo "<html><body><h1>Picture $file</h1><a href=\"$this_url?fullpic=$file\"><img src=\"$this_url?showmedpic=$file\"></body></html>";
+       } else {
+               header("Status: 403 i dont think so");
+               return;
+       }
+       return;
+} else if(isset($_REQUEST["showmedpic"])) {
+       if(preg_match("/.*\/+.*/", $_REQUEST["showmedpic"])) {
+               error_log("throwing 403");
+               header("Status: 403 i dont think so");
+               return;
+       }
+       $afile = "$show_dir/".$_REQUEST["showmedpic"];
+       if(file_exists($afile)) {
+               header('Content-Type: image/jpeg');
+               $src = imagecreatefromjpeg($afile);
+               list($width, $height) = getimagesize($afile);
+       
+               if($width <= $med_size && $height <= $med_size) {
+                       // just pump out the pic
+                       error_log("pic pump");
+                       header('Content-Type: image/jpeg');
+                       echo file_get_contents($afile);
+                       return;
+               }
+               
+               // else, resize it
+               if($width > $height) {
+                       $nw = $med_size;
+                       $nh = (int)($height/($width/$med_size));
+               } else {
+                       $nh = $med_size;
+                       $nw = (int)($width/($height/$med_size));
+                               
+               }
+       
+               /*
+                * 2000
+               * 1800
+               * $nw = 200
+               * $mul = $height/$width/200
+               */
+       
+               // error_log("neww = $nw, $nh");
+               $thumb = imagecreatetruecolor($nw, $nh);
+       
+               imagecopyresized($thumb, $src, 0, 0, 0, 0, $nw, $nh, $width, $height);
+               imagejpeg($thumb);
+       } else {
+               header("Status: 404 Not Found");
+       }
 } else if(isset($_REQUEST["showtmp"])) {
        // nothing yet
-       if(preg_match("/.*\\+.*/", $_REQUEST["showtmp"])) {
+       if(preg_match("/.*\/+.*/", $_REQUEST["showtmp"])) {
                error_log("throwing 403");
                header("Status: 403 i dont think so");
                return;
@@ -40,11 +120,11 @@ if(isset($_REQUEST["showpic"])) {
                list($width, $height) = getimagesize($afile);
                
                if($width > $height) {
-                       $nw = 200;
-                       $nh = (int)($height/($width/200));
+                       $nw = $thumb_size;
+                       $nh = (int)($height/($width/$thumb_size));
                } else {
-                       $nh = 200;
-                       $nw = (int)($width/($height/200));
+                       $nh = $thumb_size;
+                       $nw = (int)($width/($height/$thumb_size));
                        
                }
                
@@ -55,7 +135,7 @@ if(isset($_REQUEST["showpic"])) {
                 * $mul = $height/$width/200
                 */
                
-               error_log("neww = $nw, $nh");
+               // error_log("neww = $nw, $nh");
                $thumb = imagecreatetruecolor($nw, $nh);
                
                imagecopyresized($thumb, $src, 0, 0, 0, 0, $nw, $nh, $width, $height);
@@ -76,7 +156,7 @@ if(isset($_REQUEST["showpic"])) {
 
        // echo "<pre>";
        // print_r($_SERVER);
-       //echo "</pre>";
+       // echo "</pre>";
        $i = 0;
 
        $dh = opendir($show_dir);
@@ -86,7 +166,7 @@ if(isset($_REQUEST["showpic"])) {
                                echo "<tr>";
                        }
                        
-                       echo "<td><a href=\"$this_url?showpic=$file\"><img src=\"$this_url?showtmp=$file\"></a></td>";
+                       echo "<td><a href=\"$this_url?medpic=$file\"><img src=\"$this_url?showtmp=$file\"></a></td>";
                        
                        if($i == ($n_per_line-1)) {
                                echo "</tr>";