Commit 90734a3c by Antti Tonkyra

Image cropping code

1 parent 11c61563
...@@ -273,6 +273,8 @@ public class UserBean implements UserBeanLocal { ...@@ -273,6 +273,8 @@ public class UserBean implements UserBeanLocal {
bimage = resized; bimage = resized;
} }
bimage = forceCrop(bimage);
ByteArrayOutputStream naamaout = new ByteArrayOutputStream(); ByteArrayOutputStream naamaout = new ByteArrayOutputStream();
try { try {
...@@ -296,6 +298,44 @@ public class UserBean implements UserBeanLocal { ...@@ -296,6 +298,44 @@ public class UserBean implements UserBeanLocal {
return userimage; return userimage;
} }
private BufferedImage forceCrop(BufferedImage source) {
int x,y,xl,yl,xh,yh,xc,yc,x0,y0,x1,y1;
double ar = CardPrintBean.ASPECT_RATIO; // x/y
x=source.getWidth();
y=source.getHeight();
xc = x/2;
yc = y/2;
if(y >= x) {
xl = x;
yl = (int)(y*((double)x/(double)y));
} else {
xl = (int)(x*((double)y/(double)x));
yl = y;
}
xh = (int)((xl/2)*ar);
yh = yl/2;
x0 = xc-xh;
x1 = xc+xh;
y0 = yc-yh;
y1 = yc+yh;
int cix = (int)(((double)xl)*ar);
int ciy = yl;
BufferedImage cropped = new BufferedImage(cix, ciy, source.getType());
Graphics2D g = cropped.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(source, 0, 0, cix, ciy, x0, y0, x1, y1, null);
g.dispose();
return cropped;
}
@Override @Override
public UserImage findUserimageFORCE(Integer id) public UserImage findUserimageFORCE(Integer id)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!