2 header('Content-Type: text/html; charset=utf-8');
3 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
7 <style type="text/css">
10 vertical-align: middle;
14 display: inline-block;
22 vertical-align: middle;
30 function getPreview($imgFile, $maxSize)
32 # example: data/myalbum/100.mypic.jpg
33 $newImgFile = "data/".dirname($imgFile)."/".$maxSize.".".basename($imgFile);
35 if (! is_file($newImgFile))
37 $img = imagecreatefromjpeg($imgFile);
41 # don't do anything if the image is already small
42 if ($w <= $maxSize and $h <= $maxSize) {
47 # create the thumbs directory recursively
48 if (! is_dir(dirname($newImgFile))) mkdir(dirname($newImgFile), 0777, true);
52 $newH = $h/($w/$maxSize);
54 $newW = $w/($h/$maxSize);
58 $newImg = imagecreatetruecolor($newW, $newH);
60 imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newW, $newH, $w, $h);
62 imagejpeg($newImg, $newImgFile);
65 imagedestroy($newImg);
68 return dirname($_SERVER["SCRIPT_NAME"])."/".$newImgFile;
71 function getAlbumPreview($dir)
73 foreach (scandir($dir) as $file) if ($file != '.' and $file != '..') {
74 if (mime_content_type("$dir/$file") == "image/jpeg")
75 return getPreview("$dir/$file", 100);
81 $shortPath = isset($_SERVER["PATH_INFO"]) ? $_SERVER["PATH_INFO"] : "";
82 if ($shortPath == '/') $shortPath = '';
83 $scriptUrlPath = substr($_SERVER["SCRIPT_NAME"], 0, -4); // trim .php
85 $imageFiles = array();
86 $otherFiles = array();
88 $realDir = "images$shortPath";
90 foreach (scandir($realDir) as $file) if ($file != '.')
94 echo "<div><a href=\"$scriptUrlPath".dirname($shortPath)."/\">..</a></div>\n";
96 elseif (is_dir("$realDir/$file"))
99 $preview = getAlbumPreview("$realDir/$file");
100 if ($preview !== '') {
101 echo "<img src=\"$preview\" /> ";
104 echo "<a href=\"$scriptUrlPath$shortPath/$file\">$file</a>";
109 $mime = mime_content_type("$realDir/$file");
111 if ($mime == "image/jpeg")
112 $imageFiles[] = $file;
114 $otherFiles[] = $file;
118 foreach ($imageFiles as $file) {
119 echo "<div class=\"square\"><div class=\"image\"><a href=\"".dirname($scriptUrlPath)."/view/$shortPath/$file\"><img src=\"".getPreview("$realDir/$file", 100)."\" /></a></div></div>\n";
122 foreach ($otherFiles as $file) {
123 echo "<div><a href=\"".dirname($scriptUrlPath)."/$realDir/$file\">$file</a></div>\n";