Library for resampling server side images using java?

I want to create a restyled (scaled down) version of images using jsp. The original images are stored as blobs in the database. I want to create a jsp that serves up a thumbnail image with acceptable quality (not pixelated) according to the width / height of the traversed image (e.g. getimage.jsp? Imageid = xxxx & maxside = 200). Can you point me to an api or open source code that I can call from the jsp page?

+1


source to share


2 answers


Java already contains libraries for image processing. It should be easy to resize the image and output from the JSP.



This servlet looks a lot like what you want your JSP to be able to do.

+2


source


Is there something wrong with the built-in Image.getScaledInstance (w, h, hints)? (*)

Use hints = Image.SCALE_SMOOTH to get an unintelligible sketch. Then use ImageIO to convert to the required format for output.



*: well yes, there is something wrong with it, it is a bit slow, but in fact with all the other network overhead to worry about this is unlikely to be a problem. It is also not the best quality when scaling images, where drawImage with BICUBIC renderinghint is more attractive. But you're only talking about zooming out for the moment.

Be sure to check the passed sizes so you can't execute your servlet passing huge sizes causing a huge memory image to be generated.

+2


source







All Articles