Forum Moderators: coopster
I have a small gallery script and I was wondering how to make it so it displays 4 before adding a <br />.
<?
// define paths
$directory = "images";
$pathrelthumb = "/path/to/$directory/thumbnails";
$paththumb = "http://path/to/$directory/thumbnails";
$pathrelbig = "/path/to/$directory";
$pathbig = "http://path/to/$directory";
// main processing
$dir_handlerelbig = @opendir($pathrelbig) or die("Unable to open $pathrelbig");
$dir_handlerelthumb = @opendir($pathrelthumb) or die("Unable to open $pathrelthumb");
while (($filethumb = readdir($dir_handlerelthumb)) && ($filebig = readdir($dir_handlerelbig)))
{
if($filethumb!="." && $filethumb!="..")
echo "<a href='$pathbig/$filebig'><img src=\"$paththumb/$filethumb\" /></a> ";
}
// close thumb directory
closedir($dir_handlerelbig);
closedir($dir_handlerelthumb);
?>
<? break;
}
?>
It would also be great if there was a good tutorial on how to automatically create 20% thumbnails of the images instead of having separate images - with aspect ratio.
Any ideas?
Thanks
if($filethumb!="." && $filethumb!="..") {
$br = ($count%4)? '<br />' : '';
echo "<a href='$pathbig/$filebig'><img src=\"$paththumb/$filethumb\" /></a> $br";
}
I can't for the life of me remember what that '%' function is called, but if someone could find it in the PHP manual that would be cool (I tried Coop, really I did!).
As for the thumbnail generater... Let me search around a bit....
[php.net...]
I built mine from that code, after having used this one [webmasterworld.com] (scroll down) for quite some time.
You are likely going to have to write something for your own purposes to do this. Ideally you could write a thumbnail generating function that takes certain variables that you may commonly use for generating thumbnails:
function genThumb($as_ratio, $compression) {
// Do gen here
}
while (($filethumb = readdir($dir_handlerelthumb)) && ($filebig = readdir($dir_handlerelbig))) {
if($filethumb!="." && $filethumb!="..") {
if ($counter++ % 4 == 3) echo "<br />";
echo "<a href='$pathbig/$filebig'><img src=\"$paththumb/$filethumb\" /></a> ";
}
}
phpThumb() -> [phpthumb.sourceforge.net...]