<?php
$dirfiles = array();
$handle=opendir('.');
while ($file = readdir($handle)) {
if
((
strtolower(strrchr($file, '.')) == ".jpg" OR
strtolower(strrchr($file, '.')) == ".jpeg" OR
strtolower(strrchr($file, '.')) == ".png" OR
strtolower(strrchr($file, '.')) == ".gif"
)
&&
(
strstr($file, ".thumb.jpg") == ''
))
{
array_push($dirfiles, $file);
}
}
sort ($dirfiles);
closedir($handle);
// Write the beginning of the basic table for displaying the thumbs.
// Modify this section to make it fit your own website.
// -----------------------------------------------------------------
echo "<table border=\"0\" width=\"100%\" id=\"table1\" cellspacing=\"10\" cellpadding=\"5\" bordercolor=\"#000000\"><tr>";
// Read the valid filenames from the array, have your way with every single one of them
// ------------------------------------------------------------------------------------
foreach($dirfiles as $aktuellesfile)
{
// Elements of the filename are cut into pieces
$dateiendung = strrchr( $aktuellesfile, '.' );
$dateiname = substr_replace ($aktuellesfile, '', -strlen($dateiendung) );
// First a routine for creating a thumb
createthumb ($dateiname, $dateiendung);
// Now open up a table cell
echo "<td width=\"180\" style=\"border-style: solid; border-width: 1px\"><center>";
// Second a routine for showing a thumb
showthumb ($dateiname, $dateiendung);
// Close the table cell
echo "</center></td>";
// And make a linebreak after every 5 thumbs
if(++$cnt % 3 == 0) echo "</tr>";
}
// Finished
exit;
// Function to create a thumbnail if it doesn't already exist
// -----------------------------------------------------------------
function createthumb ($thumbdateiname, $thumbdateiendung)
{
$fullname = $thumbdateiname.$thumbdateiendung;
$fullthumbname = $thumbdateiname.$thumbdateiendung.".thumb.jpg";
// If thumb exists,nothing will happen
if (file_exists($fullthumbname) OR strstr($fullname, ".thumb.jpg") != '')
{
}
// If thumb doesn't exist,it's created now
else
{
if ((strtolower($thumbdateiendung) == ".jpg") OR (strtolower($thumbdateiendung) == ".jpeg")){
$src_img = imagecreatefromjpeg($fullname);
}
if (strtolower($thumbdateiendung) == ".gif"){
$src_img = imagecreatefromgif($fullname);
}
if (strtolower($thumbdateiendung) == ".png"){
$src_img = imagecreatefrompng($fullname);
}
$origx=imagesx($src_img);
$origy=imagesy($src_img);
// Maximum width and height of the thumbnails
$max_x = 180;
$max_y = 135;
// Calc, if thumb has has to be squeezed from width or height
if($origx >= $origy AND $origx > $max_x)
{
$faktor = $origx / $max_x;
$new_x = $origx / $faktor;
$new_y = $origy / $faktor;
}
elseif($origy > $origx AND $origy > $max_y)
{
$faktor = $origy / $max_y;
$new_x = $origx / $faktor;
$new_y = $origy / $faktor;
}
else
{
$new_x = $origx;
$new_y = $origy;
}
// Squeeze and write it into a file
$dst_img = imagecreatetruecolor($new_x,$new_y);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_x,$new_y,imagesx($src_img),imagesy($src_img));
imagejpeg($dst_img, $fullthumbname, 50);
}
}
// Function to show a thumbnail
// -----------------------------------------------------------------
function showthumb ($thumbdateiname, $thumbdateiendung)
{
$fullname = $thumbdateiname.$thumbdateiendung;
$fullthumbname = $thumbdateiname.$thumbdateiendung.".thumb.jpg";
if (file_exists($fullthumbname))
{
echo "<a href=\"template.php?page=$fullname&heading=$thumbdateiname\" onclick=\"openMaxWindow(this.href);return false;\"><img src =\"$fullthumbname\" border=\"0\"></a>";
}
else
{
}
}
?>