Scripts
Foto Album met Thumbnails
Na hier een compleet te veranderen fotoalbum script. Alles zelf gemaakt op 1 ding na en dat is het stukje dat de thumbnails maakt. bron: http://phphulp.nl/php/scripts/7/508/ Hoop dat jullie er wat aan hebben, en ik krijg graag reactie op mijn script waar ik iets mee kan. Dus kritiek mag maar vertel wel waarom en eventueel hoe het beter kan. Gr, Milo
foto-album-met-thumbnails
[code]
<?php
// Fotoalbum.php
// Copyright @ party-vision.nl
// De map waar je in zit
if(!isset($_GET['dir']))
{
$directory = 'PAGINAS/ALBUMS';
}
else
{
$directory = $_GET['dir'];
}
// Toegestane extensies
$ext = array('jpg', 'jpeg', 'gif', 'png', 'JPG', 'JPEG', 'GIF', 'PNG');
// Map voor thumbnails
$thumb = 'thumbs';
// Afmetingen voor thumbs
$width = 120;
$height = 90;
// Stylesheet invoegen
echo '<link rel="stylesheet" type="text/css" href="Fotoalbum.css" />';
// Begin fotoalbums
echo '<div class="fotoalbum">';
// De navigatie
echo '<div class="navigatie">';
$array = explode('/', $directory);
array_shift($array);
$aantal = count($array);
for($i = 0; $i < $aantal; $i++)
{
echo '<a class="nav" href="?page='.$_GET['page'].'&dir=PAGINAS/'.($i-2>=0 ? $array[($i-2)].'/' : NULL).($i-1>=0 ? $array[($i-1)].'/' : NULL).$array[$i].'">'.ucwords(strtolower($array[$i])).'</a>';
if($i < ($aantal - 1))
{
echo ' » ';
}
}
echo '</div>';
// Kijken of het wel een echte dir is.
if(is_dir($directory))
{
// De directory openen
if($open = @opendir($directory))
{
// Alle files loopen
while(FALSE !==($file = readdir($open)))
{
// Alleen als de file anders is als ., .. en $thumb mag ie door.
if($file != '.' && $file != '..' && $file != $thumb)
{
// Alles in een array zetten
$arrayfile[] = $file;
// Extensie checken
if(in_array(substr($file, -3), $ext) OR in_array(substr($file, -4), $ext))
{
if(!file_exists($thumb.'/'.$file))
{
// De dir aanmaken waar thumbs inkomen
@mkdir($directory.'/'.$thumb, 0775);
// Thumbs maken
$imagehw = getimagesize($directory.'/'.$file);
$src_width = $imagehw[0];
$src_height = $imagehw[1];
$src_width > $src_height ? $dest_width = $width : $dest_width = $height;
$tmp = $src_width / $dest_width;
$dest_height = $src_height / $tmp;
$src_img = imagecreatefromjpeg($directory.'/'.$file);
$dst_img = imagecreatetruecolor($dest_width,$dest_height);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height);
imagejpeg($dst_img, $directory.'/'.$thumb.'/'.$file, $width);
imagedestroy($src_img);
imagedestroy($dst_img);
}
}
}
}
closedir($open);
}
// De array netjes sorteren
sort($arrayfile);
// Dan de array openen
foreach($arrayfile as $file)
{
if($file != '.' && $file != '..' && $file != $thumb)
{
// Kijken of het een toegestaan bestand is.
if(in_array(substr($file, -3), $ext) OR in_array(substr($file, -4), $ext))
{
if(file_exists($directory.'/'.$file))
{
// Afbeelding maten ophalen
$afb = getimagesize($directory.'/'.$file);
if($afb[0] > $afb[1])
{
echo '<div class="lijst"><a href="'.$directory.'/'.$file.'" target="_blank"><img class="foto1" src="'.$directory.'/'.$thumb.'/'.$file.'"></a></div>';
}
else
{
echo '<div class="lijst"><a href="'.$directory.'/'.$file.'" target="_blank"><img class="foto2" src="'.$directory.'/'.$thumb.'/'.$file.'"></a></div>';
}
}
}
elseif(is_dir($directory.'/'.$file)) // Als het een map is
{
echo '<div class="lijst"><a class="map" href="?page='.$_GET['page'].'&dir='.$directory.'/'.$file.'">'.$file.'</a></div>';
}
}
}
}
else
{
echo 'De directory die jij zoekt ( '.$album.' ) bestaat niet';
}
echo '</div>';
?>
[/code]
en
[code]
/* Fotoalbum.css */
/* Copyright @ Party-vision.nl */
div.fotoalbum {
width: 450px;
padding-top: 2px;
}
div.navigatie {
width: 450px;
height: 18px;
font-family: Verdana;
font-size: 11px;
color: #313031;
line-height: 16px;
margin-bottom: 5px;
padding-left: 5px;
-moz-border-radius: 5px;
background-color: #3992AD;
}
a.nav:link, a.nav:hover, a.nav:active, a.nav:visited {
font-family: Verdana;
font-size: 11px;
color: #313031;
text-decoration: none;
}
/* De foto */
div.lijst {
width: 140px;
height: 140px;
float: left;
margin: 5px;
}
img.foto1 {
width: 120px;
height: 90px;
margin-left: 10px;
margin-top: 25px;
border: 1px solid grey;
}
img.foto2 {
width: 90px;
height: 120px;
margin-left: 25px;
margin-top: 10px;
border: 1px solid grey;
}
a.map {
width: 120px;
height: 120px;
display: block;
margin: 10px;
line-height: 120px;
text-align: center;
font-weight: bold;
text-decoration: none;
color: #313031;
background-image: url('IMAGES/folder.gif');
}
[/code]
Reacties
0