I need to allow users to upload files and pictures. When they upload pictures, I need to create thumbnail for them on the fly. Is there any taglibs or java source to do this from JSP or servlets?

Christopher Schultz

Writing your own thumbnail generator is not very hard, either.

I would also recommend that you generate the thumbnails a single time, instead of wasting your processor time re-generating the thumbnails on each request. Pick a good file naming convention and use it to generate the thumbnails when the user first uploads their image.

In any case, the way to play with images is this:

  1. Load the image form a file (or byte array) using java.awt.Toolkit.createImage
  2. Create a new BufferedImage with the desired size
  3. Get a Graphics object from the BufferedImage
  4. Draw (and scale) your Image on to the Graphics object either with a method that scales your Image for you, or after calling Image.getScaledImage
  5. Use a com.sun.image.codec.jpeg.JPEGImageEncoder to turn your BufferedImage into a JPEG file

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact