Added support for specifying size as width or height by appending either w or h, for example size=504h
This commit is contained in:
parent
20ce7267cd
commit
09dbe61782
1 changed files with 13 additions and 3 deletions
|
|
@ -96,7 +96,7 @@ public class AlbumServlet
|
|||
|
||||
try {
|
||||
res.setContentType("image/jpeg");
|
||||
scaleImage(req, res, file, Integer.parseInt(req.getParameter("size")));
|
||||
scaleImage(req, res, file, req.getParameter("size"));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("sadness", e);
|
||||
}
|
||||
|
|
@ -106,7 +106,7 @@ public class AlbumServlet
|
|||
}
|
||||
|
||||
|
||||
void scaleImage(HttpServletRequest req, HttpServletResponse res, File file, int size) throws IOException, JpegProcessingException, MetadataException, ParseException {
|
||||
void scaleImage(HttpServletRequest req, HttpServletResponse res, File file, String size) throws IOException, JpegProcessingException, MetadataException, ParseException {
|
||||
|
||||
List<Entry> entries = dao.read(file.getParentFile());
|
||||
Entry entry = null;
|
||||
|
|
@ -118,7 +118,17 @@ public class AlbumServlet
|
|||
}
|
||||
}
|
||||
Dimension orig = entry.getSize();
|
||||
Dimension outd = orig.scaled(size);
|
||||
Dimension outd;
|
||||
if (size.endsWith("h")) {
|
||||
int height = Integer.parseInt(size.substring(0, size.length() - 1));
|
||||
outd = orig.scaleHeight(height);
|
||||
} else if (size.endsWith("w")) {
|
||||
int width = Integer.parseInt(size.substring(0, size.length() - 1));
|
||||
outd = orig.scaleWidth(width);
|
||||
} else {
|
||||
int worh = Integer.parseInt(size);
|
||||
outd = orig.scaled(worh);
|
||||
}
|
||||
|
||||
Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("jpg");
|
||||
ImageReader reader = readers.next();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue