initial
authorpaulr <me@pjr.cc>
Mon, 28 Nov 2011 02:09:43 +0000 (13:09 +1100)
committerpaulr <me@pjr.cc>
Mon, 28 Nov 2011 02:09:43 +0000 (13:09 +1100)
show.php [new file with mode: 0644]

diff --git a/show.php b/show.php
new file mode 100644 (file)
index 0000000..701a301
--- /dev/null
+++ b/show.php
@@ -0,0 +1,108 @@
+<?php
+
+/* This is a very simple app
+ * - you give it a directory where it'll look for jpg's and it'll give a quick index
+ * 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"];
+
+
+if(isset($_REQUEST["showpic"])) {
+       // show the pic requested...
+       if(preg_match("/.*\\+.*/", $_REQUEST["showpic"])) {
+               header("Status: 403 i dont think so");
+               error_log("throwing 403");
+               return;
+       }
+       
+       $afile = "$show_dir/".$_REQUEST["showpic"];
+       if(file_exists($afile)) {
+               header('Content-Type: image/jpeg');
+               echo file_get_contents($afile);
+       } else {
+               header("Status: 404 Not Found");
+       }
+} else if(isset($_REQUEST["showtmp"])) {
+       // nothing yet
+       if(preg_match("/.*\\+.*/", $_REQUEST["showtmp"])) {
+               error_log("throwing 403");
+               header("Status: 403 i dont think so");
+               return;
+       }
+       $afile = "$show_dir/".$_REQUEST["showtmp"];
+       if(file_exists($afile)) {
+               header('Content-Type: image/jpeg');
+               $src = imagecreatefromjpeg($afile);
+               list($width, $height) = getimagesize($afile);
+               
+               if($width > $height) {
+                       $nw = 200;
+                       $nh = (int)($height/($width/200));
+               } else {
+                       $nh = 200;
+                       $nw = (int)($width/($height/200));
+                       
+               }
+               
+               /*
+                * 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");
+       }
+       return;
+} else {
+       
+       // show a grid of images
+       ?>
+<html>
+<body>
+<h1>Temp Show</h1>
+<table>
+<?php
+
+       // echo "<pre>";
+       // print_r($_SERVER);
+       //echo "</pre>";
+       $i = 0;
+
+       $dh = opendir($show_dir);
+       while (($file = readdir($dh)) !== false) {
+               if(preg_match("/.*\.[jJ][pP][gG]$/", $file)) {
+                       if($i == 0) {
+                               echo "<tr>";
+                       }
+                       
+                       echo "<td><a href=\"$this_url?showpic=$file\"><img src=\"$this_url?showtmp=$file\"></a></td>";
+                       
+                       if($i == ($n_per_line-1)) {
+                               echo "</tr>";
+                               $i = 0;
+                       } else {
+                               $i++;
+                       }
+               }
+       }
+               
+
+?>
+</table>
+</body>
+</html>
+<?php
+       
+}
+?>
\ No newline at end of file