Forum Moderators: coopster

Message Too Old, No Replies

Thumbnail gallery help please

Help with thumbnail gallery

         

music_man

4:59 am on Sep 30, 2005 (gmt 0)

10+ Year Member



Hi

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>&nbsp;";
}

// 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

music_man

9:08 am on Oct 3, 2005 (gmt 0)

10+ Year Member



bump...

mipapage

10:03 am on Oct 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For the break, I would use a count that increments in your while loop, and then check to see if $count is a multiple of four:

if($filethumb!="." && $filethumb!="..") {
$br = ($count%4)? '<br />' : '';
echo "<a href='$pathbig/$filebig'><img src=\"$paththumb/$filethumb\" /></a>&nbsp;$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....

mipapage

10:37 am on Oct 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For the thumbnails, I would try some of the scripts used on this page:

[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

}

music_man

7:16 pm on Oct 3, 2005 (gmt 0)

10+ Year Member



if($filethumb!="." && $filethumb!="..") {
$br = ($count%4)? '<br />' : '';
echo "<a href='$pathbig/$filebig'><img src=\"$paththumb/$filethumb\" /></a>&nbsp;$br";
}

does not seem to work for some reason.

should br be define above using for ($br=0 $br<0 $br++)?

Thank you for your replies.

MindlessXD

2:51 am on Oct 9, 2005 (gmt 0)

10+ Year Member



% is the modulo operator (http://en.wikipedia.org/wiki/Modulo_operation)

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>&nbsp;";
}
}

Notawiz

3:37 pm on Oct 9, 2005 (gmt 0)

10+ Year Member



Hi,

I use the phpThumb class, and it does all you need.
Google for it, as I don't remember where I got it.

Cheers.
Notawiz

MindlessXD

8:49 pm on Oct 9, 2005 (gmt 0)

10+ Year Member



oops... in my last post the "if ($counter..." line should come after the "echo..." line :/

phpThumb() -> [phpthumb.sourceforge.net...]