Forum Moderators: coopster

Message Too Old, No Replies

Don't know how to tackle script...

         

lZakl

5:05 pm on Jan 13, 2005 (gmt 0)

10+ Year Member



I am charged with what I am assuming is a pretty straight forward script...

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

ergophobe

5:42 pm on Jan 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You will need to read the filelist from the directory using readdir() [php.net]

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.

lZakl

5:54 pm on Jan 13, 2005 (gmt 0)

10+ Year Member



ergophobe,

This is exactly the sort of jumpstart I needed! I will get started this afternoon researching and hacking. I'll report back with my success (if there is success! lol) Thanks!

-- Zak

willybfriendly

6:39 pm on Jan 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want to avoid reinventing the wheel, do a search for phpthumb, which will take care of the thumb creation part pretty handily.

WBF

ergophobe

8:03 pm on Jan 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks WBF, I didn't know about that. Undoubtedly a much better way to start than what I suggested!

FTR I like reinventing the wheel - my car would handle terribly with stone wheels ;-)

lZakl

12:12 am on Jan 14, 2005 (gmt 0)

10+ Year Member



willybfriendl, that phpthumb works pretty good! I spent half the afternoon trying to figure out how to install ImageMagick, and still had gotten nowhere!

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

ergophobe

1:23 am on Jan 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is this a shared/managed hosting situation or are you running your own server? It is commonly installed somewhere on shared servers (because it's used in gallery and some CMS systems) and it is also common that your tech support would be willing to do the install for you. Check on that first before you go to too much trouble.

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.

lZakl

4:37 pm on Jan 14, 2005 (gmt 0)

10+ Year Member



It was really easy using the phpthumb module. THe site is hosted through Yahoo... and if you've ever listened to their tech support, they read what they have on the computer in fron of them. I doubt, though I'll try, they could tell me what is installed and what isn't. I wish the business I am doing the site for would switch hosts, but they are dead set on Yahoo... I don't really like the limitations Yahoo has. For instance, the don't allow ANY files that START with a "." Oh that wouldn't be THAT big of a deal except I can't use an .htaccess file. lol. Interesting host. Lots of options, but at the same time lots of limitations.

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>
<?php

if ($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.