3 Bizou - a (french) KISS php image gallery
4 Copyright (C) 2010 Marc MAURICE
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 function getPreview($imgFile, $maxSize = THUMB_SIZE)
24 # example: data/myalbum/100.mypic.jpg
25 $newImgFile = DATA_DIR."/".dirname($imgFile)."/".$maxSize.".".basename($imgFile);
27 if (! is_file($newImgFile))
29 $ext = strtolower(substr($imgFile, -4));
31 $img = imagecreatefromjpeg($imgFile);
33 $img = imagecreatefrompng($imgFile);
37 # don't do anything if the image is already small
38 if ($w <= $maxSize and $h <= $maxSize) {
43 # create the thumbs directory recursively
44 if (! is_dir(dirname($newImgFile))) mkdir(dirname($newImgFile), 0777, true);
48 $newH = $h/($w/$maxSize);
50 $newW = $w/($h/$maxSize);
54 $newImg = imagecreatetruecolor($newW, $newH);
56 imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newW, $newH, $w, $h);
59 imagejpeg($newImg, $newImgFile);
61 imagepng($newImg, $newImgFile);
64 imagedestroy($newImg);
67 return dirname($_SERVER["SCRIPT_NAME"])."/".$newImgFile;
70 function getAlbumPreview($dir)
72 foreach (scandir($dir) as $file) if ($file != '.' and $file != '..') {
73 $ext = strtolower(substr($file, -4));
74 if ($ext == ".jpg" or $ext == ".png")
75 return getPreview("$dir/$file");
81 $scriptUrlPath = $_SERVER["SCRIPT_NAME"];
83 // if url == http://localhost/photos/index/toto/titi, path_info == /toto/titi
84 // if url == http://localhost/photos/index, path_info is not set
85 // if url == http://localhost/photos/, path_info is not set
86 // if path_info is not set, we are at top level, so we redirect to /photos/index/
87 if (! isset($_SERVER["PATH_INFO"])) {
88 header("Location: $scriptUrlPath/");
92 $shortPath = $_SERVER["PATH_INFO"];
93 if ($shortPath == '/') $shortPath = '';
94 // extra security check to avoid /photos/index/../.. like urls, maybe useless but..
95 if (strpos($shortPath, '..') !== false) die(".. found in url");
98 $imageFiles = array();
99 $otherFiles = array();
101 $realDir = IMAGES_DIR.$shortPath;
103 if (! is_dir($realDir)) {
104 header("HTTP/1.1 404 Not Found");
105 die("Directory Not Found");
108 foreach (scandir($realDir) as $file) if ($file != '.' and $file != '..')
110 if (is_dir("$realDir/$file"))
112 $folders[] = array( "name" => $file, "link" => "$scriptUrlPath$shortPath/$file", "preview" => getAlbumPreview("$realDir/$file") );
116 $ext = strtolower(substr($file, -4));
117 if ($ext == ".jpg" or $ext == ".png") {
119 $link = dirname($scriptUrlPath)."/view.php$shortPath/$file";
121 $link = dirname($scriptUrlPath)."/$realDir/$file";
123 $imageFiles[] = array( "name" => $file, "url" => getPreview("$realDir/$file"), "link" => $link );
126 $otherFiles[] = array( "name" => $file, "link" => dirname($scriptUrlPath)."/$realDir/$file" );
131 if (dirname($shortPath) !== '')
132 $parentLink = $scriptUrlPath.dirname($shortPath);
138 ///// template starts here /////
139 header('Content-Type: text/html; charset=utf-8');
140 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
144 <style type="text/css">
152 text-decoration: none;
155 display: inline-block;
158 width: <?php echo THUMB_SIZE ?>px;
159 height: <?php echo THUMB_SIZE ?>px;
162 vertical-align: middle;
165 height: <?php echo THUMB_SIZE ?>px;
167 vertical-align: middle;
180 <?php if ($parentLink !== '') { ?>
181 <div id="parentfolder"><a href="<?php echo $parentLink ?>">^</a></div>
184 <?php foreach($folders as $folder) { ?>
186 <?php if ($folder["preview"] === "") { ?>
187 <a href="<?php echo $folder["link"] ?>"><?php echo $folder["name"] ?></a>
189 <div class="square"><div class="image"><a href="<?php echo $folder["link"] ?>"><img src="<?php echo $folder["preview"] ?>" /></a></div></div>
190 <div class="square"><div class="foldername"><a href="<?php echo $folder["link"] ?>"><?php echo $folder["name"] ?></a></div></div>
195 <?php foreach ($imageFiles as $file) { ?>
196 <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>
199 <?php foreach ($otherFiles as $file) { ?>
200 <div class="miscfile"><a href="<?php echo $file["link"] ?>"><?php echo $file["name"] ?></a></div>