BrightSide Workbench Full Report + Source Code
org.turro.elephant.impl.util.Thumbs Class Reference
Collaboration diagram for org.turro.elephant.impl.util.Thumbs:

Public Member Functions

 Thumbs (HttpServletRequest request)
 
String getThumb (String file, int maxDim, String rotate)
 
void createThumb (String rotate, String file, String thumb, int maxDim)
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 36 of file Thumbs.java.

Constructor & Destructor Documentation

◆ Thumbs()

org.turro.elephant.impl.util.Thumbs.Thumbs ( HttpServletRequest  request)

Definition at line 40 of file Thumbs.java.

40  {
41  this.request = request;
42  this.context = request.getSession().getServletContext();
43  }

Member Function Documentation

◆ 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.

63  {
64 
65  String filePath = context.getRealPath(file),
66  thumbPath = context.getRealPath(thumb);
67 
68  try {
69 
70  File fi = new File(filePath);
71 
72  // maximum dimension
73  if(maxDim <= 0) maxDim = 200;
74 
75  if(needsRecreateThumb(thumbPath, maxDim)) {
76 
77  BufferedImage inImage = ImageIO.read(fi);
78 
79  // Determine the scale.
80  double scale = (double)maxDim/(double)inImage.getWidth(null);
81 // if (inImage.getHeight(null) > inImage.getWidth(null)) {
82 // scale = (double)maxDim/(double)inImage.getHeight(null);
83 // }
84 
85  if(inImage.getWidth() <= maxDim/* && inImage.getHeight() <= maxDim*/) {
86  scale = 1;
87  }
88 
89  // Determine size of new image.
90  //One of them should equal maxDim.
91  int scaledW = (int)(scale*inImage.getWidth(null));
92  int scaledH = (int)(scale*inImage.getHeight(null));
93 
94  // Create an image buffer in
95  //which to paint on.
96  BufferedImage outImage;
97  if(":L".equals(rotate) || ":R".equals(rotate))
98  outImage = new BufferedImage(
99  scaledH, scaledW, BufferedImage.TYPE_INT_RGB);
100  else
101  outImage = new BufferedImage(
102  scaledW, scaledH, BufferedImage.TYPE_INT_RGB);
103 
104  // Set the scale.
105  AffineTransform tx = new AffineTransform();
106 
107  // If the image is smaller than
108  //the desired image size,
109  // don't bother scaling.
110  if (scale < 1.0d) {
111  tx.scale(scale, scale);
112  }
113 
114  if(":L".equals(rotate)) {
115  // 90 to left
116  tx.translate(inImage.getHeight(), 0);
117  tx.rotate(Math.PI/2);
118  }
119  else if(":R".equals(rotate)) {
120  // 90 to right
121  tx.translate(0, inImage.getWidth());
122  tx.rotate(-(Math.PI/2));
123  }
124 
125  // Paint image.
126  Graphics2D g2d = outImage.createGraphics();
127  g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
128  g2d.drawImage(inImage, tx, null);
129  g2d.dispose();
130 
131  File fo = new File(thumbPath);
132  ImageIO.write(outImage, "jpg", fo);
133 
134 
135  }
136 
137  } catch(Exception ex) {
138  Logger.getLogger(Thumbs.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
139  }
140  }
Thumbs(HttpServletRequest request)
Definition: Thumbs.java:40
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getThumb()

String org.turro.elephant.impl.util.Thumbs.getThumb ( String  file,
int  maxDim,
String  rotate 
)

Definition at line 46 of file Thumbs.java.

46  {
47  String contextPath = request.getContextPath(),
48  fileNoContext = file;
49 
50  if(contextPath.length() > 1 && file.startsWith(contextPath)) {
51  fileNoContext = file.substring(contextPath.length());
52  }
53  String filePath = fileNoContext,
54  thumbPath = insertThumb(fileNoContext);
55 
56  if(filePath.indexOf("_thumb") > -1) return file;
57 
58  createThumb(rotate, filePath, thumbPath, maxDim);
59 
60  return insertThumb(file);
61  }
void createThumb(String rotate, String file, String thumb, int maxDim)
Definition: Thumbs.java:63
Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following file: