Hallo!
Um Bilder aus einem Ordner auf meiner Webseite anzeigen zu lassen benutze ich folgenden Programmcode: ...s.u. Jetzt möchte ich noch, dass ein Bild welches mit $width_max = 500 auf meinen Seite angezeigt wird, zusätzlich mit einem Link oder so in seiner vollen Größen auf einen neuen leeren Seite angezeigt wird.
Da ich nicht so erfahren bin, gelingt es mir nicht. Ich hoffe, dass mir einer weiterhelfen kann.
Gruß, Frank
PROGRAMMCODE
config.php:
<? // image directory $images_dir = './';
// min width of image $width_min = 100 ; // odstep od zdjecia w poziomie $vspace = 20 ; // odstep od zdjecia w pionie $hspace = 20 ; // border of image $border = 0;
// sorting // SORT_ASC, SORT_DESC $sort = SORT_ASC;
// width of full image // if original width, set this variable to 0 $width_max = 500 ;
// show filename below image // 1 = YES, 0 = NO $filename = 1;
// number of cols $no_cols = 3;
// number of images on the site ( = number rows x number cols) $no_pics_per_page = 12;
?>
index.php:
<? if(is_file('../config.cfg.php')) require '../config.cfg.php'; else die('Error, no config file');
if(!is_dir($images_dir)) die('Error, no image directory');
?> <?php $location = "../../../"; $title = "Konzerte"; $title_1 = "Photos"; $document = "Zita Swoon"; $link = "concerts.php"; $link_1 = "concerts_2.php"; require ($location."head.inc"); require ($location."content.inc"); require ($location."config.php"); ?> <?
$time_start = microtime(true);
$noimage = 0;
if ($dh = opendir($images_dir)) { while (($f = readdir($dh)) !== false) { if((substr(strtolower($f),-3) == 'jpg') || (substr(strtolower($f),-3) == 'jpg')) { $imageinfo = getimagesize($images_dir.$f); $width = $imageinfo[0]; $height = $imageinfo[1]; $size = round(filesize($images_dir.$f)/1024,1).' KB'; $noimage++; $images[] = array('filename' => $f, 'width' => $width, 'height' => $height, 'size' => $size); array_multisort($images, $sort, SORT_REGULAR); } } closedir($dh); }
if($noimage) {
if($_GET["img"] != '') { echo '<p class="name">'.$images[$_GET["img"]][filename].'</p>'; if($images[$_GET["img"]][filename] != '') {
if($_GET["img"]) $no = ceil(($_GET["img"]+1)/$no_pics_per_page); else $no = 1;
if($_GET["img"] == 0) $side = '<p class="link"><a href="'.$_SERVER["PHP_SELF"].'?no='.$no.'" class="link">up</a> <a href="'.$_SERVER["PHP_SELF"].'?img='.($_GET["img"]+1).'" class="link">next >></a></p>'; elseif($_GET["img"] == ($noimage-1)) $side = '<p class="link"><a href="'.$_SERVER["PHP_SELF"].'?img='.($_GET["img"]-1).'" class="link"><< prev</a> <a href="'.$_SERVER["PHP_SELF"].'?no='.$no.'" class="link">up</a></p>'; else $side = '<p class="link"><a href="'.$_SERVER["PHP_SELF"].'?img='.($_GET["img"]-1).'" class="link"><< prev</a> <a href="'.$_SERVER["PHP_SELF"].'?no='.$no.'" class="link">up</a> <a href="'.$_SERVER["PHP_SELF"].'?img='.($_GET["img"]+1).'" class="link">next >></a></p>'; echo $side.'<p align="center"><img class= "link" src="picture.php?img='.$images[$_GET["img"]][filename].'&show=full" border="'.$border.'" hspace="'.$hspace.'" vspace="'.$vspace.'" alt="'.$images[$_GET["img"]][filename].'" title="'.$images[$_GET["img"]][filename].', '.$images[$_GET["img"]][width].'x'.$images[$_GET["img"]][height].', '.$images[$_GET["img"]][size].'" ></p>'.$side; } } else { // echo $noimage.'<br>'.print_r($images); if($noimage > $no_pics_per_page) $norows = ceil($no_pics_per_page/$no_cols); else $norows = ceil($noimage/$no_cols);
$nopos = ceil($noimage/$no_pics_per_page);
// echo $nopos; echo '<table border="0" align="center" cellpadding="0" cellspacing="0"> ';
if($_GET["no"] == "") $no = 1; else $no = $_GET["no"];
$index=abs($no-1)*$no_pics_per_page; if(($noimage-$index)<$no_pics_per_page) $norows= ceil(($noimage-$index)/$no_cols);
for($a = 1;$a<=$norows;$a++) { echo ' <tr> '; for($b = 1;$b<=$no_cols;$b++) { if($images[$index][filename] != '') { echo '<td width="'.(2*$vspace+$width_min).'" valign="top" align="center"><a href="'.$_SERVER["PHP_SELF"].'?img='.$index.'" ><img class="link"src="picture.php?img='.$images[$index][filename].'" border="'.$border.'" hspace="'.$hspace.'" vspace="'.$vspace.'" alt="'.$images[$index][filename].'" title="'.$images[$index][filename].', '.$images[$index][width].'x'.$images[$index][height].', '.$images[$index][size].'"></a> '; if($filename) echo '<span class="name">'.$images[$index][filename].'</span><br><br>';
echo '</td>'; $index++; } else echo '<td width="'.(2*$vspace+$width_min).'"> </td>'; } echo '</tr> '; }
echo ' </table> ';
if($nopos>1) { echo '<p class="link">'; for($i=1;$i<=$nopos;$i++) { if($i == $no) echo '<font>'.$i.'</font> '; else echo '<a href="'.$_SERVER["PHP_SELF"].'?no='.$i.'">'.$i.'</a> '; } echo '</p>'; }
}
} else die('No images in directory');
$time_end = microtime(true); $time = $time_end - $time_start;
require ($location."content_end.inc"); require ($location."foot.inc"); ?>
und.... pictue.php:
<?
if(is_file('../config.cfg.php')) require '../config.cfg.php'; else die('Error, no config file');
if($_GET[img] == "") exit;
if (!ereg('[1][^/]*$', $_GET[img])) exit;
$image = $images_dir.$_GET[img]; $new_w = $width_min; $imagedata = getimagesize($image);
// echo $image; if(!$imagedata[0]) exit();
$new_h = (int)($imagedata[1]*($new_w/$imagedata[0]));
if($_GET["show"] == "full") { if($width_max) { if($imagedata[0]<$width_max) { $new_w = $imagedata[0]; $new_h = $imagedata[1]; } else { $new_w = $width_max; $new_h = (int)($imagedata[1]*($new_w/$imagedata[0])); } } else { $new_w = $imagedata[0]; $new_h = $imagedata[1]; } }
if(strtolower(substr($_GET[img],-3)) == "jpg") { header("Content-type: image/jpg"); $dst_img=ImageCreate($new_w,$new_h); $src_img=ImageCreateFromJpeg($image); $dst_img = imagecreatetruecolor($new_w, $new_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img)); $img = Imagejpeg($dst_img); }
if(substr($_GET[img],-3) == "gif") { header("Content-type: image/gif"); $dst_img=ImageCreate($new_w,$new_h); $src_img=ImageCreateFromGif($image); ImagePaletteCopy($dst_img,$src_img); ImageCopyResized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img)); $img = Imagegif($dst_img); }
?>
^./ ↩︎