Link to home
Start Free TrialLog in
Avatar of AntoniRyszard
AntoniRyszard

asked on

Using thumbnail images in jsp?

Hello,

In my java web application, I will have a number of images stored on the server and wish to display these as thumbnails in a .jsp. Allowing the user to click on the thumbnail to display the full-sized image in a new browser window.

The number of images on the server will be increasing on a regular bases.

I was trying to plan how to approach this, and wondered if anyone could offer some advise?

With the image number increasing on the server, should I thinking of creating a permanent thumbnail of each and display these in the jsp. Even though creating a thumbnail can be an expensive exercise.

Are there other approaches? Should I be limiting the number of thumbnails displayed on each page?

Thanks
Avatar of d_g_watson
d_g_watson

You could create the thumbnail the first time the image is displayed and store it on disk. The next time the thumbnail page is displayed, the image will already exist and will not have to be generated - so the expensive part is only done once per image. I've done something similar to this and thought it worked quite well.

I would limit the number of thumbnails on the page depending on the size of the thumbnail images, and the potential for a particular set to grow.

ASKER CERTIFIED SOLUTION
Avatar of Mayank S
Mayank S
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
(in that case you don't need to create a new thumbnail, you use the existing image as a thumbnail by showing it in a smaller size)
That will cause the full size image to be downloaded to the browser. The browser will then scale the image for display. The object here is to reduce the amount of data being transferred from the server.

Please correct me if I'm wrong.
Avatar of AntoniRyszard

ASKER

Thanks

Could I ask when creating the thumbnail images, which java classses you used.

I used the Java 2D API, but I don't have a lot of experience with it. I used the technique described on this forum post:

http://forum.java.sun.com/thread.jspa?threadID=522483

Note: this technique will not work on a headless system. There are probably ways to change it to work in such an environment, but I didn't look into that as it wasn't a problem for me.

>> That will cause the full size image to be downloaded to the browser

True. But it saves you from creating thumbnails for new images everytime. Otherwise, of course, you can create a file-monitor for a directory (which contains the actual images) so that whenever it recognizes new files being put over there, it can raise an event to create a new thumb-nail image out of it using Java image API through scaling.
You don't even need a file monitor. You know what thumbnails you'll need from the directory containing the actual images. When you're rendering the page you can check if the corresponding thumbnail exists for each image in the actual image dir. If it doesn't, create it. If it does, do nothing.
The problem with that is that if the thumbnail does not exist, you will be creating it at that time (so the response might be slight slower due to that process because it will involve reading the whole image once). If you have an asynchronous file monitor or batch process kind of thing to sync up images and thumbnails, you can be assured that in 99% of the cases, you will have the thumbnails (unless the image was placed just now and in the millisecond before which the thumbnail got created, you got a request for it).
Thanks I have lots to think about.

Sure, take your time.