3 define('THUMB_SIZE', 100);
5 function getPreview($imgFile, $maxSize = THUMB_SIZE)
7 # example: data/myalbum/100.mypic.jpg
8 $newImgFile = "data/".dirname($imgFile)."/".$maxSize.".".basename($imgFile);
10 if (! is_file($newImgFile))
12 $img = imagecreatefromjpeg($imgFile);
16 # don't do anything if the image is already small
17 if ($w <= $maxSize and $h <= $maxSize) {
22 # create the thumbs directory recursively
23 if (! is_dir(dirname($newImgFile))) mkdir(dirname($newImgFile), 0777, true);
27 $newH = $h/($w/$maxSize);
29 $newW = $w/($h/$maxSize);
33 $newImg = imagecreatetruecolor($newW, $newH);
35 imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newW, $newH, $w, $h);
37 imagejpeg($newImg, $newImgFile);
40 imagedestroy($newImg);
43 return dirname($_SERVER["SCRIPT_NAME"])."/".$newImgFile;
46 function getAlbumPreview($dir)
48 foreach (scandir($dir) as $file) if ($file != '.' and $file != '..') {
49 if (strtolower(substr($file, -4)) == ".jpg")
50 return getPreview("$dir/$file");
56 $shortPath = isset($_SERVER["PATH_INFO"]) ? $_SERVER["PATH_INFO"] : "";
57 if ($shortPath == '/') $shortPath = '';
58 $scriptUrlPath = substr($_SERVER["SCRIPT_NAME"], 0, -4); // trim .php
61 $imageFiles = array();
62 $otherFiles = array();
64 $realDir = "images$shortPath";
66 foreach (scandir($realDir) as $file) if ($file != '.' and $file != '..')
68 if (is_dir("$realDir/$file"))
70 $folders[] = array( "name" => $file, "link" => "$scriptUrlPath$shortPath/$file", "preview" => getAlbumPreview("$realDir/$file") );
74 $ext = strtolower(substr($file, -4));
76 $imageFiles[] = array( "name" => $file, "url" => getPreview("$realDir/$file"), "link" => dirname($scriptUrlPath)."/view/$shortPath/$file" );
78 $otherFiles[] = array( "name" => $file, "link" => dirname($scriptUrlPath)."/$realDir/$file" );
82 if (dirname($shortPath) !== '')
83 $parentLink = $scriptUrlPath.dirname($shortPath);
89 ///// template starts here /////
90 header('Content-Type: text/html; charset=utf-8');
91 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
95 <style type="text/css">
98 vertical-align: middle;
102 display: inline-block;
106 width: <?php echo THUMB_SIZE ?>px;
107 height: <?php echo THUMB_SIZE ?>px;
110 vertical-align: middle;
116 <?php if ($parentLink !== '') { ?>
117 <div id="parentfolder"><a href="<?php echo $parentLink ?>">^</a></div>
120 <?php foreach($folders as $folder) { ?>
122 <a href="<?php echo $folder["link"] ?>">
123 <?php if ($folder["preview"] !== "") { ?>
124 <img src="<?php echo $folder["preview"] ?>" />
126 <?php echo $folder["name"] ?>
131 <?php foreach ($imageFiles as $file) { ?>
132 <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>
135 <?php foreach ($otherFiles as $file) { ?>
136 <div class="miscfile"><a href="<?php echo $file["link"] ?>"><?php echo $file["name"] ?></a></div>