I have found a image script that will automatically thumbnail for me but shows them all on one page. The problem I have is that my my image folders can contain quite a few images and I was wondering if anybody here could help me so that the script only shows 27 images per page. I have tried to contact the original writer of the script and haven't heard back from the person, I would greatly appreciate if somebody here could help me out.
Here is the script:
<?php
// TStarGallery 1.0 engine
// With basic PHP knowledge you can understand what's happening here.
// Don't blame me for writing non-perfect code for I do not care.
// If there is an error or something, mail me at tstar @ taillandier.de
// Read the current directory, throw out non-jpg/gif/png + thumbfiles
// --------------------------------------------------------------------
$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, "_t.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 width=\"505\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" id=\"structure\"><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>";
// Second a routine for showing a thumb
showthumb ($dateiname, $dateiendung);
// Close the table cell
echo "</td>";
// And make a linebreak after every 3 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."_t.jpg";
// If thumb exists,nothing will happen
if (file_exists($fullthumbname) OR strstr($fullname, "_t.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 = 150;
$max_y = 150;
// 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."_t.jpg";
if (file_exists($fullthumbname))
{
echo "<a href=\"$fullname\"><img src =\"$fullthumbname\" border=\"0\"></a>";
echo "<!-- =========================== -->";
echo "<!-- powered by TStarGallery 1.0 -->";
echo "<!-- =========================== -->";
}
else
{
}
}
?>
Here is the script:
<?php
// TStarGallery 1.0 engine
// With basic PHP knowledge you can understand what's happening here.
// Don't blame me for writing non-perfect code for I do not care.
// If there is an error or something, mail me at tstar @ taillandier.de
// Read the current directory, throw out non-jpg/gif/png + thumbfiles
// --------------------------------------------------------------------
$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, "_t.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 width=\"505\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" id=\"structure\"><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>";
// Second a routine for showing a thumb
showthumb ($dateiname, $dateiendung);
// Close the table cell
echo "</td>";
// And make a linebreak after every 3 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."_t.jpg";
// If thumb exists,nothing will happen
if (file_exists($fullthumbname) OR strstr($fullname, "_t.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 = 150;
$max_y = 150;
// 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."_t.jpg";
if (file_exists($fullthumbname))
{
echo "<a href=\"$fullname\"><img src =\"$fullthumbname\" border=\"0\"></a>";
echo "<!-- =========================== -->";
echo "<!-- powered by TStarGallery 1.0 -->";
echo "<!-- =========================== -->";
}
else
{
}
}
?>
Comment