Forum Moderators: coopster
What they are looking for:
A page, when opened will dynamically create a thumbnail page based on images in a specified directory. So say I had 20 images in the /images dir, I would get a page with 20 thumbs, one of each image, and the image name below it.
Problem:
I know this is possible, however I've hit a mind-block. It's like going out to the shed after 20 years of crap has piled up in it and saying "Where do I begin?" I thought I'd ask for some input on where to start... I mean I know I am going to be looking at a loop that says "for each image...", but I am stumped after that! I have searched google, and come up with 200 ways to read, write and append text files! Any input -- direction is gladly accepted!
-- Zak
If you come across a directory other than "." or ".." you will need to drill down to that directory and parse it (this will require using recursive functions if you need this).
You can determine whether what you have retrieved is a file or a dir by using functions like is_file() [php.net] and is_dir() [php.net].
Once you know it's a file, you find out whether it's a jpeg. You can test this in various ways, but you may be able to simply check whether the last few characters are .jpg or .jpeg and assume that those are all jpegs and all jpegs have one of those endings.
Once you know you have a jpeg, you must create a thumbnail. You can use the GD library [us3.php.net], but you will get nicer looking thumbnails if you use ImageMagick [imagemagick.org] or NetPBM [netpbm.sourceforge.net] (actually, I haven't tried NetPBM myself except once but I've heard that it has similar quality to ImageMagick).
Once you have the thumbnails, the rest should be cake.
ergophobe, I would however, like to try ImageMagick also, but can't figure out the install. All I can find in my searches is:
1) It requires Shell access to your remote host (which I have)
and 2) PHP 4.0 or better (Which my host also provides)
I can't find any REAL step-by-step instructions for installing it. Keep in mind I am a person who has little SHELL experience and limited knowlege of UNIX commands.
Do you have any input on this?
-- Zak
Failing that, you should have an install document in the download package.
You can also google on
imagemagick installation
imagemagick install
and turn up lots of pages. Start with that and see if you can find some guidance there.
Here is the code I came up with to simply list the photos. I am working on the second version where I now take the # of photos, divide by 4 and create a table for each set of four. Should have that done this afternoon (maybe!).
<html>
<body>
<center>
<H1>This is my prototype!</H1><br><br>
<?phpif ($handle = opendir('/tableinv')) { /* Just a test directory. */
while (false!== ($file = readdir($handle))) {
if($file!="." && $file!=".."){
echo "$file\n<br>";
$ext = substr($file,strrpos($file,'.'));
$fn = str_replace(".JPG", "", $file);
if ($ext == ".JPG")
{
echo "<IMG SRC=\"pic/phpThumb.php?src=../tableinv/$file&w=100\"><br>";
echo "This pictures name is: <b>$fn</b> <br><br>";
}
}
}
closedir($handle);
}
?>
</center>
</body>
</html>
Thanks ergophobe for your help. I am going to contact his host within the next couple of hours and see what they offer as far as ImageMagick.