Sætte max sider i side tal. og sætte tabel til 100%
Hej eksperten,Jeg har dette billedarkiv-script, og jeg har to ting som jeg bare ikke kan få til at gøre som jeg vil.
1. De tal der står over billederne, de komme i en lille kollone. Altså de er mast sammen.
2. Så står der for mange sider. Der skal maz. stå 6 sider. Altså ligesom; 1 2 3 4 5 6 og så senere 12 13 14 15 16 17.
Og ja.. :D jeg har prøvet, men kan sq ikke. :D
Her er koden:
<font face=verdana size=1>
<?php
//Configuration
//Title for your gallery that will be used with the default header.
$title="";
//Thumbnail size. The minimum width and height in pixels, that you would like the thumbnails to be. Photos are scaled.
$twidth=200;
$theight=200;
//Photo size. The minimum width and height in pixels, that you would like you photos scaled to when displayed.
$pwidth = 1024;
$pheight = 768;
//The thumbnail gallery is displayed in a table. Please choose the number of rows and columns you would like.
$rows=5;
$cols=2;
//If you would like the filename of the photo to be displayed under the thumbnail change this setting.
//0=off 1=on
$showfilename=1;
//If you would like photo to up a new window when clicked change this setting.
//The defualt is to open the image up in the same browser window.
//0=off 1=on
$window=1;
//If you would like to use a custom header or footer please add the file names here and they will be included in the script.
//Otherwise the plain jane default will be used. The files should be in the same folder as the script, but if you provide an
//alternate path it will work as well. Example: header.html, header.php.
$header="NULL";
$footer="NULL";
//No need to mess with anything below here.
//Part of this function comes from http://www.php.net/manual/en/function.getimagesize.php
function thumb_maker($filename, $minwidth, $minheight) {
if (file_exists($filename."thmb.jpg")) {
$photosize = getimagesize($filename."thmb.jpg");
if (max($minwidth,$minheight)!=max($photosize[0],$photosize[1])) {
unlink($filename."thmb.jpg");
}
}
if (!file_exists($filename."thmb.jpg") && file_exists($filename)) {
echo "";
set_time_limit(60);
$photosize = getimagesize($filename);
// Get image size and scale ratio
$scale = min($minwidth/$photosize[0], $minheight/$photosize[1]);
if ($scale < 1) {
$width = floor($scale*$photosize[0]);
$height = floor($scale*$photosize[1]);
}
else {
$width = $minwidth;
$height = $minheight;
}
if ($photosize[mime]=="image/jpeg") {
$resizedimage = imagecreatetruecolor($width, $height);
$thumbimage = imagecreatefromjpeg($filename);
imagecopyresampled($resizedimage, $thumbimage, 0, 0, 0, 0, $width, $height, $photosize[0], $photosize[1]);
imagejpeg($resizedimage,$filename."thmb.jpg",50);
imageDestroy($resizedimage);
imageDestroy($thumbimage);
}
}
}
//Part of this function comes from http://www.php.net/manual/en/function.getimagesize.php
function gallery_sizer($photo,$minwidth,$minheight) {
if (file_exists($photo)) {
$photosize = getimagesize("$photo");
# Get image size and scale ratio
$scale = min($minwidth/$photosize[0], $minheight/$photosize[1]);
if ($scale <= 1) {
$width = floor($scale*$photosize[0]);
$height = floor($scale*$photosize[1]);
}
return array($width,$height,$photosize[0],$photosize[1]);
}
}
function getdirs($dir) {
$dirs=array();
chdir($dir);
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".."){
if (is_dir($file)) {
$dirs[] = $file;
}
}
}
closedir($handle);
}
sort($dirs);
return $dirs;
}
function getphotos($photodir) {
$photos=array();
if ($handle = opendir($photodir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && !eregi(".jpgthmb.jpg$",$file) && eregi(".jpg$",$file)){
$photos[] = $file;
}
}
closedir($handle);
}
sort($photos);
return $photos;
}
function thumb_gallery($photonum) {
global $photos, $photourl, $photodir, $twidth, $theight, $rows, $cols, $showfilename, $album, $window;
if (($photonum)>(count($photos)-($rows*$cols))) {
$photonum=(count($photos)-($rows*$cols));
}
if (($photonum)<=0) {
$photonum=0;
}
if(isset($album)) { $query="&album=".urlencode($album); }
for ($tr = 1; $tr <= $rows; $tr++) {
$photobody[]="<tr>";
for ($td = 1; $td <= $cols; $td++) {
$photobody[]="<td align=\"center\">";
$size=gallery_sizer($photodir."/".$photos[$photonum]."thmb.jpg",$twidth,$theight);
$link = $photourl."/".$photos[$photonum]."thmb.jpg";
if ($window==1) { $target="_blank"; } else { $target="_self"; }
if ($photonum<=count($photos)-1) { $photobody[]="<a href=\"$_SERVER[PHP_SELF]?p=$photos[$photonum]$query\" target=\"$target\"><img src=\"$link\" width=\"$size[2]\" height=\"$size[3]\" alt=\"$photos[$photonum]\" border=0></a><br />"; }
if ($showfilename==1) { $photobody[]=$photos[$photonum]; }
$photobody[]="</td>";
$photonum++;
}
$photobody[]="</tr>";
}
unset($tr, $td);
#this id down here for a reason don't move it and use array_unshift instead. Trust me.
if (($photonum-($rows*$cols))>0) { $prev="<a href=\"$_SERVER[PHP_SELF]?pn=".($photonum-(($rows*$cols)*2)).$query."\"><font face=Verdana size=1><< Tilbage</font></a>"; }
if (($photonum)<(count($photos))) { $next="<a href=\"$_SERVER[PHP_SELF]?pn=".$photonum.$query."\"><font face=verdana size=1>Frem>></font></a><font face=verdana size=1>"; }
$photopage=array();
$photopage[]="Sider: ";
for ($pagelink=0, $pagenum=1; $pagelink<=count($photos); $pagelink+=($rows*$cols), $pagenum++) {
$photopage[]="<a href=\"$_SERVER[PHP_SELF]?pn=".($pagelink).$query."\"><font face=verdana size=1>$pagenum</font></a> | ";
}
unset($pagelink, $pagenum);
$photopage=implode("", $photopage);
array_unshift($photobody, "<tr><td colspan=".$cols."><table width=\"100%\" border=\"0\"><tr><td width=\"33%\"><div align=\"LEFT\">".$prev."</div></td><td width=\"33%\"><div align=\"CENTER\"><font face=verdana size=1>Billeder <strong>".($photonum-(($rows*$cols)-1))."</strong> til <strong>".$photonum."</strong> ud af <strong>".count($photos)."</strong><br />".$photopage."<font face=verdana size=1></div></td><td width=\"33%\"><div align=\"RIGHT\">".$next."</font></div></td></tr></table></td></tr>");
#put the table tag at the top of the array.
array_unshift($photobody, '<table width="100%" border="0" cellspacing="0" cellpadding="3">');
$photobody[]='</table>';
return $photobody;
}
function photo_gallery($photo, $pwidth, $pheight) {
global $photodir, $photourl, $thumbsurl, $window;
$photobody=array();
if (isset($photo)) {
$size=gallery_sizer("$photodir/$photo",640,640);
$photobody[]='<table width="100%" border="0" cellspacing="0" cellpadding="3">';
$photobody[]='<tr><td colspan="3" align="center"></td></tr>';
if ($window==1) { $target="<a href=\"java script:window.close()\"><a font face=verdana size=1>Luk vinduet</font></a>"; } else { $target="<a href=\"".$_SERVER[HTTP_REFERER]."\"><font face=verdana size=1>Tilbage</font></a>"; }
$photobody[]="<tr class=\"imageborder\"><td>".$target."</td><td align=\"center\"><div align=\"CENTER\" class=\"caption\"></div></td><td align=\"right\"> </td></tr>";
$photobody[]='<tr><td colspan="3" align="center">';
$photobody[]="<img src=\"$photourl/$photo\" border=1 alt=\"\" class=\"imageborder\">";
$photobody[]='</td></tr>';
$photobody[]="<tr class=\"imageborder\"><td align=\"center\" colspan=\"3\"><div align=\"CENTER\" class=\"caption\"></div></td></tr>";
$photobody[]="<tr class=\"imageborder\"><td>".$target."</td><td align=\"center\"><div align=\"CENTER\" class=\"caption\"></div></td><td align=\"right\"> </td></tr>";
$photobody[]='</table>';
}
return $photobody;
}
function display($photobody) {
global $photodir;
getheader();
albums($photodir);
foreach ($photobody as $value) {
echo $value."\n";
}
getfooter();
exit;
}
function albums($dir) {
//for now only one level of albums works.
global $album, $title;
$dirs=getdirs($dir);
if (isset($album)) { echo "<h1 align=\"center\">".$album."</h1>"; } else { echo "<h1 align=\"center\">".$title."</h1>"; }
echo "<div align=\"center\">";
if (isset($album)) { echo "<a href=\"".$_SERVER[PHP_SELF]."\">$title</a>\n"; } else { }
if (count($dirs)>0) {
foreach ($dirs as $value) {
echo "<a href=\"".$_SERVER[PHP_SELF]."?album=".urlencode($value)."\">".$value."</a>\n";
}
}
echo "</div>";
}
//returns the header for the page. Checks for a user defined header.
function getheader() {
global $header, $title;
if (isset($header) && $header!="NULL" && is_file ($header)) {
require("$header");
}
else {
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">';
echo '<html>';
echo '<head>';
echo "<title>$title</title>";
echo '</head>';
echo '<body>';
}
}
//returns the footer for the page. Checks for a user defined footer.
function getfooter() {
global $footer;
if (isset($footer) && $footer!="NULL" && is_file ($footer)) {
require("$footer");
}
else {
echo "</body>\n</html>";
}
}
$photodir= dirname($_SERVER['PATH_TRANSLATED']);
$photourl=dirname($_SERVER[PHP_SELF]);
$thumbsurl=dirname($_SERVER[PHP_SELF]);
$photobody=array();
if (isset($_GET[album])) {
$album = urldecode($_GET[album]);
$photodir=dirname(realpath($_SERVER['PATH_TRANSLATED']))."/".$album;
$photourl=dirname($_SERVER[PHP_SELF])."/".$album;
$thumbsurl=dirname($_SERVER[PHP_SELF])."/".$album;
}
//To make sure this works both on Linux and Win
$photodir = str_replace("\\", "/", $photodir);
//Get the jpegs from the folder.
$photos=getphotos($photodir);
//check to see if thumbnails are made if not it will make. Adds time to the processing of the script.
for ($i=0; $i<=count($photos)-1; $i++) {
thumb_maker($photodir."/".$photos[$i], $twidth, $theight);
}
if (count($photos)<=0) {
echo "No JPEG photos in the folder to display";
exit;
}
if (isset($_GET[pn])) {
$photonum = $_GET[pn];
$photobody=thumb_gallery($photonum);
}
elseif (isset($_GET[p])) {
$photo=$_GET[p];
$photobody=photo_gallery($photo,$pwidth, $pheight);
}
else {
$photobody=thumb_gallery(0);
}
//output it all to the browser.
display($photobody);
exit;
?>
</font>
