@RequestParam(value = "x", required = false) Integer x,
@RequestParam(value = "y", required = false) Integer y,
HttpSession session, HttpServletRequest request) throws Exception {
Image image = null;
if (x != null && y != null) {
try {
image = imageDao.findBySource(id, "x=" + x + ",y=" + y);
if (image != null) {
log.debug("thumb found");
}
} catch (HibernateException hex) {
log.debug("search image", hex);
}
}
if (image == null) {
image = imageDao.findById(id);
if (x != null && y != null) {
ImageResizer resizer = new ImageResizer();
Image thumb = new Image();
thumb.setFileName("th_" + image.getFileName());
log.debug("resizing image: " + image.getId() + " " + image.getImageBuf().length + " bytes");
long start = System.currentTimeMillis();
thumb.setImageBuf(resizer.resize2(image.getImageBuf(), x, y));
log.debug("... " + (System.currentTimeMillis() - start) / 1000);
thumb.setResolution("x=" + x + ",y=" + y);
thumb.setSource(image);
imageDao.makePersistent(thumb);
image = thumb;
}
}