3 function getPreview($imgFile, $maxSize)
5 # example: data/myalbum/100.mypic.jpg
6 $newImgFile = "data/".dirname($imgFile)."/".$maxSize.".".basename($imgFile);
8 if (! is_file($newImgFile))
10 $img = imagecreatefromjpeg($imgFile);
14 # don't do anything if the image is already small
15 if ($w <= $maxSize and $h <= $maxSize) {
20 # create the thumbs directory recursively
21 if (! is_dir(dirname($newImgFile))) mkdir(dirname($newImgFile), 0777, true);
25 $newH = $h/($w/$maxSize);
27 $newW = $w/($h/$maxSize);
31 $newImg = imagecreatetruecolor($newW, $newH);
33 imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newW, $newH, $w, $h);
35 imagejpeg($newImg, $newImgFile);
38 imagedestroy($newImg);
41 return dirname($_SERVER["SCRIPT_NAME"])."/".$newImgFile;
44 function getAlbumPreview($dir)
46 foreach (scandir($dir) as $file) if ($file != '.' and $file != '..') {
47 if (strtolower(substr($file, -4)) == ".jpg")
48 return getPreview("$dir/$file", 100);
54 $shortPath = isset($_SERVER["PATH_INFO"]) ? $_SERVER["PATH_INFO"] : "";
55 if ($shortPath == '/') $shortPath = '';
56 $scriptUrlPath = substr($_SERVER["SCRIPT_NAME"], 0, -4); // trim .php
59 $imageFiles = array();
60 $otherFiles = array();
62 $realDir = "images$shortPath";
64 foreach (scandir($realDir) as $file) if ($file != '.' and $file != '..')
66 if (is_dir("$realDir/$file"))
68 $folders[] = array( "name" => $file, "link" => "$scriptUrlPath$shortPath/$file", "preview" => getAlbumPreview("$realDir/$file") );
72 $ext = strtolower(substr($file, -4));
74 $imageFiles[] = array( "name" => $file, "url" => getPreview("$realDir/$file", 100), "link" => dirname($scriptUrlPath)."/view/$shortPath/$file" );
76 $otherFiles[] = array( "name" => $file, "link" => dirname($scriptUrlPath)."/$realDir/$file" );
80 if (dirname($shortPath) !== '')
81 $parentLink = $scriptUrlPath.dirname($shortPath);
87 ///// template starts here /////
88 header('Content-Type: text/html; charset=utf-8');
89 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
93 <style type="text/css">
96 vertical-align: middle;
100 display: inline-block;
108 vertical-align: middle;
114 <?php if ($parentLink !== '') { ?>
115 <div id="parentfolder"><a href="<?php echo $parentLink ?>">^</a></div>
118 <?php foreach($folders as $folder) { ?>
120 <a href="<?php echo $folder["link"] ?>">
121 <?php if ($folder["preview"] !== "") { ?>
122 <img src="<?php echo $folder["preview"] ?>" />
124 <?php echo $folder["name"] ?>
129 <?php foreach ($imageFiles as $file) { ?>
130 <div class="square"><div class="image"><a href="<?php echo $file["link"] ?>"><img src="<?php echo $file["url"] ?>" alt="<?php echo $file["name"] ?>" /></a></div></div>
133 <?php foreach ($otherFiles as $file) { ?>
134 <div class="miscfile"><a href="<?php echo $file["link"] ?>"><?php echo $file["name"] ?></a></div>