|
| Thumbs (HttpServletRequest request) |
|
String | getThumb (String file, int maxDim, String rotate) |
|
void | createThumb (String rotate, String file, String thumb, int maxDim) |
|
- Author
- Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g
Definition at line 36 of file Thumbs.java.
◆ Thumbs()
org.turro.elephant.impl.util.Thumbs.Thumbs |
( |
HttpServletRequest |
request | ) |
|
Definition at line 40 of file Thumbs.java.
41 this.request = request;
42 this.context = request.getSession().getServletContext();
◆ createThumb()
void org.turro.elephant.impl.util.Thumbs.createThumb |
( |
String |
rotate, |
|
|
String |
file, |
|
|
String |
thumb, |
|
|
int |
maxDim |
|
) |
| |
Definition at line 63 of file Thumbs.java.
65 String filePath = context.getRealPath(file),
66 thumbPath = context.getRealPath(thumb);
70 File fi =
new File(filePath);
73 if(maxDim <= 0) maxDim = 200;
75 if(needsRecreateThumb(thumbPath, maxDim)) {
77 BufferedImage inImage = ImageIO.read(fi);
80 double scale = (double)maxDim/(
double)inImage.getWidth(
null);
85 if(inImage.getWidth() <= maxDim) {
91 int scaledW = (int)(scale*inImage.getWidth(
null));
92 int scaledH = (int)(scale*inImage.getHeight(
null));
96 BufferedImage outImage;
97 if(
":L".equals(rotate) ||
":R".equals(rotate))
98 outImage =
new BufferedImage(
99 scaledH, scaledW, BufferedImage.TYPE_INT_RGB);
101 outImage =
new BufferedImage(
102 scaledW, scaledH, BufferedImage.TYPE_INT_RGB);
105 AffineTransform tx =
new AffineTransform();
111 tx.scale(scale, scale);
114 if(
":L".equals(rotate)) {
116 tx.translate(inImage.getHeight(), 0);
117 tx.rotate(Math.PI/2);
119 else if(
":R".equals(rotate)) {
121 tx.translate(0, inImage.getWidth());
122 tx.rotate(-(Math.PI/2));
126 Graphics2D g2d = outImage.createGraphics();
127 g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
128 g2d.drawImage(inImage, tx,
null);
131 File fo =
new File(thumbPath);
132 ImageIO.write(outImage,
"jpg", fo);
137 }
catch(Exception ex) {
138 Logger.getLogger(
Thumbs.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
Thumbs(HttpServletRequest request)
◆ getThumb()
String org.turro.elephant.impl.util.Thumbs.getThumb |
( |
String |
file, |
|
|
int |
maxDim, |
|
|
String |
rotate |
|
) |
| |
Definition at line 46 of file Thumbs.java.
47 String contextPath = request.getContextPath(),
50 if(contextPath.length() > 1 && file.startsWith(contextPath)) {
51 fileNoContext = file.substring(contextPath.length());
53 String filePath = fileNoContext,
54 thumbPath = insertThumb(fileNoContext);
56 if(filePath.indexOf(
"_thumb") > -1)
return file;
60 return insertThumb(file);
void createThumb(String rotate, String file, String thumb, int maxDim)
The documentation for this class was generated from the following file: