Det er bestemt ikke smukt...
Men se eksemplet her:
http://www.codebreaker.dk/exp/galleri/index.phpOg koden her:
<?php
//http://www.eksperten.dk/spm/693433
function resize( $filename, $newfilename, $maxw, $maxh )
{
$srcim = imagecreatefromjpeg( $filename );
$ow = imagesx($srcim);
$oh = imagesy($srcim);
$wscale = $maxw / $ow;
$hscale = $maxh / $oh;
$scale = ( $hscale < $wscale ? $hscale : $wscale );
$nw = round( $ow * $scale, 0 );
$nh = round( $oh * $scale, 0 );
$dstim = imagecreatetruecolor( $nw, $nh );
imagecopyresampled( $dstim, $srcim, 0, 0, 0, 0, $nw, $nh, $ow, $oh );
imagejpeg( $dstim, $newfilename, 85 );
imagedestroy( $dstim );
imagedestroy( $srcim );
return file_exists($newfilename);
}
function showGallery($path=NULL)
{
$output = '';
$count = 0;
$pics = 5;
if(empty($path))
{
$path = "./";
}
else
{
$path = $path . "/";
}
foreach (glob($path."*",GLOB_ONLYDIR) as $dir)
{
$jpgs = glob($dir."/thumb_{*.jpg, *jpeg, *.jpe}",GLOB_BRACE);
if(count($jpgs)>0)
{
srand((float)microtime() * 1000000);
shuffle($jpgs);
$jpg = end($jpgs);
if($count >= $pics)
{
echo "<br />";
$count = 0;
}
$count++;
$output .= '<a href="./index.php?dir='.$dir.'"><img src="'.$jpg.'" /></a>' . "\n";
}
else
{
$output .= '<a href="./index.php?dir='.$dir.'"><img src="no_thumb.png" /></a>' . "\n";
}
}
foreach (glob($path."{*.jpg, *jpeg, *.jpe}",GLOB_BRACE) as $jpg)
{
$file = $path . basename($jpg);
if(!file_exists($path . 'thumb_' . basename($jpg)) && !preg_match('/\/thumb_/', $file))
{
resize($jpg,$path . 'thumb_' . basename($jpg),100,100);
}
$thumb = $path . "thumb_" . basename($jpg);
if(!preg_match('/\/thumb_/', $file))
{
$output .= '<a target="blank" href="'.$jpg.'"><img src="'.$thumb.'" /></a>' . "\n";
}
}
return $output;
}
echo showGallery($_GET['dir']);
?>