Gossamer Forum
Home : Products : DBMan : Customization :

Automatic Thumbnails

(Page 1 of 3)
> >
Quote Reply
Automatic Thumbnails
OK, we've managed to come up with a way of automatically thumbnailing uploaded images for use within a database. This mod will not only reduce the dimensions of the image, but also the file size.

To work you MUST have ImageMagick or JPJTN modules installed. These may already be installed on your server (try running PERLDIVER from www.perlarchive.com to see what modules you have installed). There is no way to run this without one of the above.

IMAGEMAGICK: (JPGTN users search perlarchive.com for the thumbnail script)
Create an empty text file called THUMBNAIL.CGI

Paste this into it:
Code:
sub thumbnail {
$CONVERT = "/usr/X11R6/bin/convert"; #location of convert program (use WHEREIS CONVERT command to find)
$THUMBNAIL_SIZE_W = 230; #pixel width of thumbnail
$THUMBNAIL_SIZE_H = 100; #pixel height of thumbnail

my ($filename) = $_[0];

$THUMBNAIL_PATH = "/home/travel/public_html/db/upload2/sml_pic"; #dir where thumbnails will be stored
$SAVE_DIRECTORY_PATH = "/home/travel/public_html/db/upload2/big_pic_temp"; #dir where large pics are found (upload directory)

$CONVERT="$CONVERT -geometry ${THUMBNAIL_SIZE_W}x${THUMBNAIL_SIZE_H}! -quality 50";

system "$CONVERT $SAVE_DIRECTORY_PATH/$filename $THUMBNAIL_PATH/$filename";

}
1;


Changing your variables where required. The ! after the sizes indicates that the image ratio should NOT be maintained (i.e. forced dimensions). The quality setting is for JPEG compression (50% here)

Now in your HTML.PL file, find HTML_UPLOAD_SUCCESS

add:

Code:
$ALLOWED_EXT =~ s/\\.//g;
$ALLOWED_EXT =~ s/\$//g;
@extensions = split (/\Q|\E/o,$ALLOWED_EXT);
GRAPHIC: foreach $extension (@extensions) {
if (-e "$SAVE_DIRECTORY/$in{$db_key}.$extension") {
$filename="$in{$db_key}.$extension";
last GRAPHIC;
}
}
require "thumbnail.cgi"; #Calls file
&thumbnail($filename); #Executes file for uploaded pic
at the top.

Ensure your thumbnail.cgi file is within the same directory.

==============================
POINTS:
You need two directories: $SAVE_DIRECTORY_PATH and $THUMBNAIL_PATH. One will be the raw images and one the thumbnailed images.

You get no feedback as to whether the thumbnail has been created as it is an 'invisible' process.

THIS MAS BEEN BRIEFLY TESTED. I'm trying to test it at the moment, but perhaps you can try it out, and post any bugs here.

I will post this in the resource centre once it has been tested.



Cheers!
Ben
------------
http://www.travel-experiences.com
Quote Reply
Re: Automatic Thumbnails In reply to
Hi Ben,

How exactly would one get this working with JPGTN? I would have to move to the BIG PICS directory, and launch JPGTN from there (which I installed it in)...for some reason JPGTN has to have the pics in its directory to thumbnail them. So is there anyway to change directories in Perl? I need something like:

cd ../../
cd pics01
jpgtn -s 130 -q 85 -d tn -p s $filename

I can't use something like "/home/www/myserver/jpgtn -s 130 -q 85 -d tn -p s $filename" because it doesn't work. Someone has to know if this is possible. Please respond...thanks!

Quote Reply
Re: Automatic Thumbnails In reply to
I'm going to be working on this in the next day or so.


JPD
Quote Reply
Re: Automatic Thumbnails In reply to
Mark,

I think you will need to have a script that will call JPGTN and run the commands. I'll have a look for one, but try searching for Thumbnails at Perl Archive.

Ben

Cheers!
Ben
------------
http://www.travel-experiences.com
Quote Reply
Re: Automatic Thumbnails In reply to
We should call this Instant Messager Threads!

Cheers!
Ben
------------
http://www.travel-experiences.com
Quote Reply
Re: Automatic Thumbnails In reply to
Hi, thanks Carol and Ben! I tried to look up "thumbnail" there before, and I just got a bunch of very expensive programs in the results. Hopefully Carol can figure this one out ;) Thanks!

Quote Reply
Re: Automatic Thumbnails In reply to
I think Carol has a copy of the script I used in conjunction with ImageMagick, so it should be quite straight forward to use it with JPGTN.

Hopefully everything will be the same, but I think that with JPGTN you can only specify the longest size of the thumbnail (not BOTH dimensions). Anyway, I think Carol is testing this out as we speak!!



Cheers!
Ben
------------
http://www.travel-experiences.com
Quote Reply
Re: Automatic Thumbnails In reply to
That's correct Ben, you can only specify the size of the longest dimension with JPGTN. The other big thing is that you can't call an image that isn't in the same directory that JPGTN is in (or at least I can't get it to work). Thanks.

Quote Reply
Re: Automatic Thumbnails In reply to
In Reply To:
you can't call an image that isn't in the same directory that JPGTN is in
I think this probably can be worked around when a script is used to call it. We'll see.....

Cheers!
Ben
------------
http://www.travel-experiences.com
Quote Reply
Re: Automatic Thumbnails In reply to
Hi Carol,

Have you had any luck with the script? Thanks!

Quote Reply
Re: Automatic Thumbnails In reply to
I have just sent a message to Carol to see how her 'experiments' went! I haven't really been looking at this myself much because I already have ImageMagick installed and working.

Hopefully Carol will be able to offer something along with the Image::Size module I found (Chris Croome is working on this with Carol).



Cheers!
Ben
------------
http://www.travel-experiences.com
Quote Reply
Re: Automatic Thumbnails In reply to
I got frustrated with it and had to get away from it for a while. I've been working on (and I think I completed) a completely different mod. Now I'm going to try to go back to the image thing. Let's see if my frustration level can be kept to a managable level. Smile


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Automatic Thumbnails In reply to
Ben, maybe you can offer me some tips on getting ImageMagick if Carol can't figure this out. I think the reason why ImageMagick is not installing properly on my ISP is because of access restrictions. I uncompress all the files okay, and run the automatic configure program, and it looks okay, but then when I test it by using "display", the file isn't found. I've also tried the "make install" process, and that's not working either. I'm guessing what ImageMagick does is install something into a bin, which I'm not allowed to access. Any thoughts? Thanks!

Quote Reply
Re: Automatic Thumbnails In reply to
ImageMagick is a very "got it or you haven't" module!!

I contacted a friend with a dedicated server and he says you need 80Mb of free space to be able to manipulate images. If you are trying to install this in your own area I think you will encounter lots of porblems. It is a HUGE module, 99.9% of which you will not use.

It just happened that my ISP already had it installed (even though they told me they hadn't!!)

That is the main reason I recommended JPGTN because it is just for thumbnailing and quite easy to install.

Cheers!
Ben
------------
http://www.travel-experiences.com
Quote Reply
Re: Automatic Thumbnails In reply to
Now that I have the size thing working -- finally!! -- I'm trying to work out the thumbnail thing with jptgn. I probably should wait to do this. After one success, my brain is completely fried. For some reason I just can't seem to understand the instructions I've been given.

Help!!

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Automatic Thumbnails In reply to
Hi Carol -

This is what I would need to type if I were in Telnet (I have no idea how to do this in Perl, which is where you come inSmile:

cd ../../ #to get back to my root directory

cd pics01 #my big picture directory

jpgtn -s 130 -q 85 -d tn -p s $filename (ID#)
#the command line, where -s is size, -q is quality, -d is the directory that the thumbnails are outputted to, -p is the prefix of the thumbnails

That's all I need (basically just to get to the directory with the big pictures (because for some reason, I can't use a path from the cgi-bin)...and to pass the ID.) Thanks.

Quote Reply
Re: Automatic Thumbnails In reply to
That's exactly the point I got to last night before I finally gave up. The directory where the original graphic is must be the current working directory.

I did see a command in another script that gave me a possible clue, though. I'm going to try it out in a few minutes. I'll post my results.


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Automatic Thumbnails In reply to
Mark, I think I'm going to have to throw in the towel on this one. I just can't get it to work. It's fine when I'm in Telnet. That little thumbnail appears just as slick as anything. But I have tried everything I can think of to write a cgi script that will do the same thing and it just ain't happening.

I can't tell you how much it bothers me to give up on something. But at some point, I have to recognize that I'm not up to the challenge. And I'm not sure that anyone is, really. I have done a pretty comprehensive search of CGI scripts and every one I've found that creates thumbnails uses ImageMagick instead of jpgtn.


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Automatic Thumbnails In reply to
Well, thanks for trying to get it Smile...I guess my only other option is to try to get ImageMagick installed...hopefully my ISP will let me do it. Thanks for everything.

Quote Reply
Re: Automatic Thumbnails In reply to
Hi!

Sorry you guys couldn't get this to work.. how ANNOYING!!!

A quick thing you could try (just to check that you don't have ImageMagick installed) is to type:

whereis Convert

at the Telnet command line. I didn't think I had it installed until i did this!

But if you are unlucky I'm really sorry! Web Hosts seem to like making people sweat for their money!

Wink

Cheers!
Ben
------------
http://www.travel-experiences.com
Quote Reply
Re: Automatic Thumbnails In reply to
Carol-

I know that you're probably sick of looking at this, but I've just found a script that looks like it does 90% of what we need to do! If you go to http://draught.caltech.edu/thumbnail/tnu/tnu.html you'll find a script that thumbnails JPGs using JPGTN and puts them in a page/index. Go down, and I think we want the lines around where it says:

system "$THUMBNAIL_PROG $THUMBNAIL_FLAGS $fn $THUMBNAIL_STDOUT_REDIRECT";

It seems like all we would have to do is pass the ID#s in and delete the unneccessary routines. Can you please take a look at this? I'll try working with it first thing when I wake up. Thanks!

Quote Reply
Re: Automatic Thumbnails In reply to
I have that file. It's still not a cgi script, but one that is run through telnet.

There is no way (as far as I can see) to change the directory using jptgn in a cgi script. And jptgn will not work unless you can change the directory.


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Automatic Thumbnails In reply to
Hi Ben-

Through some miracle from my tireless complaing, my host put up ImageMagick!!!! Now I installed the script and CGI file, and they work great...but do you know how to batch convert using the line command? I tried

/usr/X11R6/bin/convert -geometry 130x130! -quality 75 /home/myserver/www/pics01/* .jpg /home/myserver/www/pics01/small/*.jpg

and similar commands, but can't seem to get it. Please let me know asap if you can. Thanks!

Quote Reply
Re: Automatic Thumbnails In reply to
Well done!! Its a great thing to have installed!!!

I haven't tried to batch convert myself..sorry! However, if you try going to www.perlarchive.com there were quite a few scripts that use ImageMagick, so you may be lucky...

...if not have you tried looking at www.imagemagick.org? You probably tried that but worth a shot. You can email them and they might be able to help!!



Cheers!
Ben
------------
http://www.travel-experiences.com
Quote Reply
Re: Automatic Thumbnails In reply to
Hi Ben and Carol-

Can we use the thumbnail routine that used to go in HTML_UPLOAD_SUCCESS with the new multiple file upload MOD (and should that go in HTML_ADD_SUCCESS)? Oh, and Ben, I've checked out the imagemagick site, to no avail - but I'll try to find the answer and post it here. Thanks. Smile

> >