Java image resizer servlet

Posted on Sun 16 December 2007 in Java

I'm working on a photo gallery application running on Java 6 using Tomcat 6, JQuery for the client side, and images and xml generated from Picasa. I needed several sizes of images for thumbnails and animations and I wasn't about to create multiple image sizes with Fireworks (I'm a lazy developer). Doing what every lazy developer does, I search Google for an image resize solution that would run on the application server and give me the sizes that I needed and take the manual work out of the equation. I found several PHP examples and disjointed Java examples, but no complete solutions. So, unfortunately I had to do some work to put something together.

Down to brass tax, here's the image resizer servlet code: (copy paste, use as you please)

Hopefully I've contributed something useful to another lazy developer and this solution works. I have no idea how scalable this solution is, nor do I care, it's just for a photo album where I needed cleanly resized images. More articles to come later on the album such as customizing and parsing xml from Picasa and a Java-based Ajax photo gallery using JQuery UI, don't hold your breath though, remember I'm lazy.