3 /* This is a very simple app
4 * - you give it a directory where it'll look for jpg's and it'll give a quick index
5 * of them along with clickable links to see the full thing
9 $n_per_line = 6; // number of pics in each line of the table
10 $thumb_size = 300; // size of thumbnails
11 $med_size = 1024; // size of "medium" image
14 $show_dir = "/net/iron/export/quickshow/";
15 $this_url = "http://".$_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"];
19 if(isset($_REQUEST["showpic"])) {
20 // show the pic requested...
21 if(preg_match("/.*\/+.*/", $_REQUEST["showpic"])) {
22 header("Status: 403 i dont think so");
23 error_log("throwing 403");
27 $afile = "$show_dir/".$_REQUEST["showpic"];
28 if(file_exists($afile)) {
29 header('Content-Type: image/jpeg');
30 echo file_get_contents($afile);
32 header("Status: 404 Not Found");
34 } else if(isset($_REQUEST["fullpic"])) {
35 $file = $_REQUEST["fullpic"];
36 if(preg_match("/.*\/+.*/", $_REQUEST["fullpic"])) {
37 error_log("throwing 403");
38 header("Status: 403 i dont think so");
41 $afile = "$show_dir/".$_REQUEST["fullpic"];
42 if(file_exists($afile)) {
43 echo "<html><body><h1>Fullsize picture $file</h1><a href=\"$this_url\"><img width=\"100%\" src=\"$this_url?showpic=$file\"></body></html>";
45 header("Status: 403 i dont think so");
49 } else if(isset($_REQUEST["medpic"])) {
50 $file = $_REQUEST["medpic"];
51 if(preg_match("/.*\/+.*/", $_REQUEST["medpic"])) {
52 error_log("throwing 403");
53 header("Status: 403 i dont think so");
56 $afile = "$show_dir/".$_REQUEST["medpic"];
57 if(file_exists($afile)) {
58 echo "<html><body><h1>Picture $file</h1><a href=\"$this_url?fullpic=$file\"><img src=\"$this_url?showmedpic=$file\"></body></html>";
60 header("Status: 403 i dont think so");
64 } else if(isset($_REQUEST["showmedpic"])) {
65 if(preg_match("/.*\/+.*/", $_REQUEST["showmedpic"])) {
66 error_log("throwing 403");
67 header("Status: 403 i dont think so");
70 $afile = "$show_dir/".$_REQUEST["showmedpic"];
71 if(file_exists($afile)) {
72 header('Content-Type: image/jpeg');
73 $src = imagecreatefromjpeg($afile);
74 list($width, $height) = getimagesize($afile);
76 if($width <= $med_size && $height <= $med_size) {
77 // just pump out the pic
78 error_log("pic pump");
79 header('Content-Type: image/jpeg');
80 echo file_get_contents($afile);
85 if($width > $height) {
87 $nh = (int)($height/($width/$med_size));
90 $nw = (int)($width/($height/$med_size));
98 * $mul = $height/$width/200
101 // error_log("neww = $nw, $nh");
102 $thumb = imagecreatetruecolor($nw, $nh);
104 imagecopyresized($thumb, $src, 0, 0, 0, 0, $nw, $nh, $width, $height);
107 header("Status: 404 Not Found");
109 } else if(isset($_REQUEST["showtmp"])) {
111 if(preg_match("/.*\/+.*/", $_REQUEST["showtmp"])) {
112 error_log("throwing 403");
113 header("Status: 403 i dont think so");
116 $afile = "$show_dir/".$_REQUEST["showtmp"];
117 if(file_exists($afile)) {
118 header('Content-Type: image/jpeg');
119 $src = imagecreatefromjpeg($afile);
120 list($width, $height) = getimagesize($afile);
122 if($width > $height) {
124 $nh = (int)($height/($width/$thumb_size));
127 $nw = (int)($width/($height/$thumb_size));
135 * $mul = $height/$width/200
138 // error_log("neww = $nw, $nh");
139 $thumb = imagecreatetruecolor($nw, $nh);
141 imagecopyresized($thumb, $src, 0, 0, 0, 0, $nw, $nh, $width, $height);
144 header("Status: 404 Not Found");
149 // show a grid of images
158 // print_r($_SERVER);
162 $dh = opendir($show_dir);
163 while (($file = readdir($dh)) !== false) {
164 if(preg_match("/.*\.[jJ][pP][gG]$/", $file)) {
169 echo "<td><a href=\"$this_url?medpic=$file\"><img src=\"$this_url?showtmp=$file\"></a></td>";
171 if($i == ($n_per_line-1)) {