PHP Single Page Gallery With Thumbnails
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ko">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="content-language" content="kr" />
<meta http-equiv="content-style-type" content="text/css" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="imagetoolbar" content="no" />
<title>Thumbnail Gallery</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js" charset="utf-8"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7/jquery-ui.min.js" charset="utf-8"></script>
<script type="text/javascript" src="/_lib/jquery.wookmark.js"></script>
<script type="text/javascript" src="/_lib/pirobox/js/pirobox_extended_min.js"></script>
<link type="text/css" rel="stylesheet" charset="utf-8" href="/_lib/pirobox/css/style_1/style.css" />
<style type="text/css">
<!--
body, html {
text-align: center;
}
#main { position: relative; margin: 20px auto; width: 80%; }
#tiles { margin: 0px; padding: 0px; list-style: none; }
#tiles li { float: left; margin: 0px; padding: 0px; }
img.pic {
margin: 0px;
border: 0px;
vertical-align: top;
}
-->
</style>
</head>
<body>
<?php if($_GET['password'] != 'password') {
echo "<form><input type='text' name='password' /><button type='submit'>비밀번호를 입력하세요.</button></form><br />";
die('access denied');
}?>
<?php
error_reporting(E_ALL);
if(!is_dir('thumbs')) mkdir('thumbs') or die('can\' create thumbs directory');
$thumb_list = array();
$pic_list = array();
if ($handle = opendir('thumbs')) {
while (false !== ($thumb_file = readdir($handle))) {
if (strtolower(array_pop(explode('.',$thumb_file))) == 'jpg') {
$thumb_list[] = $thumb_file;
}
}
closedir($handle);
}
if ($handle = opendir('.')) {
while (false !== ($pic_file = readdir($handle))) {
if (strtolower(array_pop(explode('.',$pic_file))) == 'jpg') {
$pic_list[] = $pic_file;
}
}
closedir($handle);
}
$count = 0;
$thumb_total = count($thumb_list);
$pic_total = count($pic_list);
if($pic_total > $thumb_total){
echo "Generating Thumbnails...<br />";
// error_reporting(E_ALL);
if(!is_dir('thumbs')) mkdir('thumbs') or die('can\' create thumbs directory');
// $pic_list = array();
// if ($handle = opendir('.')) {
// while (false !== ($pic_file = readdir($handle))) {
// if (strtolower(array_pop(explode('.',$pic_file))) == 'jpg') {
// $pic_list[] = $pic_file;
// }
// }
// closedir($handle);
// }
// $count = 0;
// $total = count($pic_list);
// $imgsize = GetImageSize($_GET['filename']);
// $width = $imgsize[0];
// $height = $imgsize[1];
// $rate = $_GET['size'] / $imgsize[0];
// $temp = (int)($imgsize[1] * $rate);
$thumbWidth = 180; // 썸네일 너비
foreach($pic_list as $pic_file) {
$save_path = getcwd().'/thumbs/';
$im = imagecreatefromjpeg($pic_file);
$rate = $thumbWidth/imagesx($im); // 비율
$thumbHeight = (int)(imagesy($im)* $rate);
$small = imagecreatetruecolor(180,$thumbHeight);
imagecopyresampled($small,$im,0,0,0,0,$thumbWidth,$thumbHeight,imagesx($im),imagesy($im));
imagejpeg($small,$save_path.$pic_file,80);
imagedestroy($im);
imagedestroy($small);
usleep(100);
set_time_limit(90);
$count++;
// echo "Working on file {$count} / {$total}<br>\n";
flush();
}
echo "end";
echo "<script type='text/javascript'>location.href = './?password=password';</script>";
} else if($pic_total > $thumb_total){
echo "Please Delete Thumbnail Files";
}
?>
<div id="status">
Total <?=$pic_total;?> Pics
</div>
<div id="main">
<ul id="tiles">
<?php
sort($thumb_list);
foreach($thumb_list as $thumb_file) {
$path = 'thumbs/'.$thumb_file;
if(!is_file($thumb_file)) continue;
echo "<li><a href=\"{$thumb_file}\" rel=\"gallery\" class=\"pirobox_gall\" title=\"{$thumb_file}\"><img src=\"{$path}\" class=\"pic\" alt=\"{$thumb_file}\"></a></li>\n";
}
?>
</ul>
</div>
<script type="text/javascript">
<!--
$(document).ready(function() {
// Prepare layout options.
var options = {
autoResize: true, // This will auto-update the layout when the browser window is resized.
container: jQuery('#main'), // Optional, used for some extra CSS styling
offset: 1 // Optional, the distance between grid items
// itemWidth: 238 // Optional, the width of a grid item
};
var $handler = jQuery('#tiles li');
timer = setInterval(function(){
// $preloader.remove();
$handler.wookmark(options);
}, 0);
$handler.click(function(e){
// handler.wookmark();
});
$('a.pirobox_gall').piroBox_ext({
piro_speed : 200,
bg_alpha : 0.9,
piro_scroll : true // pirobox always positioned at the center of the page
});
});
-->
</script>
</body>
</html>