define("BG_COL", "#000000"); // Background color of webpage
define("FG_COL", "#ffffff"); // Foreground color of webpage. Also controls link and text color
#define("BG_COL", "#ffffff");
#define("FG_COL", "#000000");
define("PREV", "Previous"); // Text on link to previous image
define("NEXT", "Next"); // Text on link to next image
# define("PREV", "Föregående");
# define("NEXT", "Nästa");
define("MAX_THUMB_X", 100); // Thumbnail bounding height
define("MAX_THUMB_Y", 70); // Thumbnail bounding width
define("MAX_RUN_X", 800); // Page width
define("PAD", 2); // Padding of thumbnails. Border size for selected image
define("CMD_CONVERT", "/usr/bin/convert"); // Path to convert binary
define("DESCR_FILE", "descr.txt"); // Look in this file for optional descriptive text
// Pick from optional descriptive text
function get_text($idx) {
if(file_exists(DESCR_FILE)) { // Go get it
$lines = file(DESCR_FILE);
return chop($lines[$idx]);
} else {
return "";
}
}
// Format nav nicely
function fmt_nav($prev, $text, $next) {
$ret = "
| ";
$ret .= "";
if($prev != "")
$ret .= "<<< (".PREV.")";
else
$ret .= "<<< (".PREV.")";
$ret .= "";
$ret .= " | ";
$ret .= "$text | ";
$ret .= "";
$ret .= "";
if($next != "")
$ret .= "(".NEXT.") >>>";
else
$ret .= "(".NEXT.") >>>";
$ret .= "";
$ret .= " |
";
return $ret;
}
?>
Album - echo get_text(0); ?>
// Get image files in current dir
$imgs = array();
$d = dir("./");
while($entry=$d->read()) {
if(ereg("^[0-9]+\.jpg$", $entry)) {
$imgs[$entry] = $entry;
}
}
$d->close();
ksort($imgs);
$run_x = 0;
// Check for cached thumbnails
reset($imgs);
while(list($key, $val) = each($imgs)) {
$img_num = substr($key, 0, -4);
$thumbname = $img_num."_".MAX_THUMB_X."_".MAX_THUMB_Y.".jpg";
if(!file_exists($thumbname)) { // Go create the cache copy
$cmd = CMD_CONVERT." -geometry ".MAX_THUMB_X."x".MAX_THUMB_Y." $key $thumbname";
exec(escapeshellcmd($cmd));
flush();
}
}
// Which image do we show?
if(!isset($img)) { // use first
reset($imgs);
list($key, $val) = each($imgs);
$use_img = $key;
} else {
$use_img = $img;
}
// Show thumbnail gallery
echo "\r\n";
$prev = $next = "";
$cnt = 0;
foreach($imgs as $key => $val) {
$cnt++;
if($last == $use_img) { // Previous was the img selected.
$next = $key; // Use this as next img
}
if($key == $use_img) { // This is the img selected
$prev = $last;
$idx = $cnt;
}
$last = $key;
$run_x += MAX_THUMB_X+PAD*2;
if($run_x > MAX_RUN_X) { // Break rows when wide enough
echo "
\r\n";
$run_x = MAX_THUMB_X+PAD*2;
}
$img_num = substr($key, 0, -4);
$thumbname = $img_num."_".MAX_THUMB_X."_".MAX_THUMB_Y.".jpg";
$thumb = getimagesize($thumbname);
$wh = $thumb[3];
// Td with thumbnail picture
echo " | \r\n";
}
echo "
\r\n";
// Top nav
echo "";
$text = get_text($idx);
$prev_text_next = fmt_nav($prev, $text, $next);
echo $prev_text_next;
echo "
\r\n";
// Show image
if($next)
echo "";
$imgsize = getimagesize($use_img);
echo "
";
if($next)
echo "";
echo "\r\n";
// Bottom nav
echo "";
echo $prev_text_next;
echo "
\r\n";
?>