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["medpic"])) {
35 $file = $_REQUEST["medpic"];
36 if(preg_match("/.*\/+.*/", $_REQUEST["medpic"])) {
37 error_log("throwing 403");
38 header("Status: 403 i dont think so");
41 $afile = "$show_dir/".$_REQUEST["medpic"];
42 if(file_exists($afile)) {
43 echo "<html><body><h1>Picture $file</h1><a href=\"$this_url?showpic=$file\"><img src=\"$this_url?showmedpic=$file\"></body></html>";
45 header("Status: 403 i dont think so");
48 } else if(isset($_REQUEST["showmedpic"])) {
49 if(preg_match("/.*\/+.*/", $_REQUEST["showmedpic"])) {
50 error_log("throwing 403");
51 header("Status: 403 i dont think so");
54 $afile = "$show_dir/".$_REQUEST["showmedpic"];
55 if(file_exists($afile)) {
56 header('Content-Type: image/jpeg');
57 $src = imagecreatefromjpeg($afile);
58 list($width, $height) = getimagesize($afile);
60 if($width <= $med_size && $height <= $med_size) {
61 // just pump out the pic
62 error_log("pic pump");
63 header('Content-Type: image/jpeg');
64 echo file_get_contents($afile);
69 if($width > $height) {
71 $nh = (int)($height/($width/$med_size));
74 $nw = (int)($width/($height/$med_size));
82 * $mul = $height/$width/200
85 // error_log("neww = $nw, $nh");
86 $thumb = imagecreatetruecolor($nw, $nh);
88 imagecopyresized($thumb, $src, 0, 0, 0, 0, $nw, $nh, $width, $height);
91 header("Status: 404 Not Found");
93 } else if(isset($_REQUEST["showtmp"])) {
95 if(preg_match("/.*\/+.*/", $_REQUEST["showtmp"])) {
96 error_log("throwing 403");
97 header("Status: 403 i dont think so");
100 $afile = "$show_dir/".$_REQUEST["showtmp"];
101 if(file_exists($afile)) {
102 header('Content-Type: image/jpeg');
103 $src = imagecreatefromjpeg($afile);
104 list($width, $height) = getimagesize($afile);
106 if($width > $height) {
108 $nh = (int)($height/($width/$thumb_size));
111 $nw = (int)($width/($height/$thumb_size));
119 * $mul = $height/$width/200
122 // error_log("neww = $nw, $nh");
123 $thumb = imagecreatetruecolor($nw, $nh);
125 imagecopyresized($thumb, $src, 0, 0, 0, 0, $nw, $nh, $width, $height);
128 header("Status: 404 Not Found");
133 // show a grid of images
142 // print_r($_SERVER);
146 $dh = opendir($show_dir);
147 while (($file = readdir($dh)) !== false) {
148 if(preg_match("/.*\.[jJ][pP][gG]$/", $file)) {
153 echo "<td><a href=\"$this_url?medpic=$file\"><img src=\"$this_url?showtmp=$file\"></a></td>";
155 if($i == ($n_per_line-1)) {