Upgradingdave
Upgradingdave

Reputation: 13056

Success stories of creating Thumbnail images on demand using java

I have a bunch of images on a server. When client requests url for image, the client can specify to either receive the full image or get a thumbnail of the image. So, I'm looking to implement a servlet type solution that processes request, and generates thumbnail on demand if needed. It needs to support jpg, gif, tif, png.

It looks like using BufferedImage, JAI, and/or ImageMagick are the best options for java (from this post). Any others I might have missed?

Also, has anyone implemented something similar in java? If so, any suggestions on a solution that gives (1) fairly descent quality thumbnails, (2) doesn't hog a huge amount of memory when it processes the images, (3) acceptable response time?

Upvotes: 1

Views: 1134

Answers (4)

texclayton
texclayton

Reputation: 189

See also Loading large images as thumbnails without memory issues in Java? for a good answer about using javax.imagio.ImageReader to create thumbnails with minimal memory overhead.

Upvotes: 1

Phil
Phil

Reputation: 11

Another solution is to do some systems call to a command line utility like non-java imagemagick and link output the generated file.

Upvotes: 1

Bozho
Bozho

Reputation: 596996

The core line of code for such a solution would be

img.getScaledInstance(w, h, Image.SCALE_DEFAULT);

Where, if you don't like the quality, you can use Image.SCALE_SMOOTH.

I've been using this (surronded by some extras, like replacing a color with a pattern), on a not-so-active site (~300 users per day), but one which serves many images, and this hasn't caused any problems, so you can freely use it.

Use ImageIO.write(image, formatName, response.getOutputStream()) for sending the image in the response.

Upvotes: 1

Related Questions