Commit ab98daf7 by Tuukka Kivilahti

Merge branch 'issue-8' into 'master'

Issue 8

Forcecrop kuville jotta backendiin menee vain oikeanlaista dataa.

Closes #8
2 parents 3b7655ce 90734a3c
...@@ -66,8 +66,7 @@ public class CardPrintBean implements CardPrintBeanLocal { ...@@ -66,8 +66,7 @@ public class CardPrintBean implements CardPrintBeanLocal {
private PrintedCardFacade printedCardFacade; private PrintedCardFacade printedCardFacade;
private static final Logger logger = LoggerFactory.getLogger(CardPrintBean.class); private static final Logger logger = LoggerFactory.getLogger(CardPrintBean.class);
private int nick_x = 0; public static final double ASPECT_RATIO = 0.7317073170731707;
private int nick_y = 0;
/** /**
* Default constructor. * Default constructor.
...@@ -144,11 +143,11 @@ public class CardPrintBean implements CardPrintBeanLocal { ...@@ -144,11 +143,11 @@ public class CardPrintBean implements CardPrintBeanLocal {
int originalHeight = faceBufferedImage.getHeight(); int originalHeight = faceBufferedImage.getHeight();
int width = originalWidth; int width = originalWidth;
int height = (int) Math.round(originalWidth * (1 / 0.7317073170731707)); int height = (int) Math.round(originalWidth * (1 / ASPECT_RATIO));
if (height > originalHeight) { if (height > originalHeight) {
height = originalHeight; height = originalHeight;
width = (int) Math.round(originalHeight * 0.7317073170731707); width = (int) Math.round(originalHeight * ASPECT_RATIO);
} }
int offsetx = (originalWidth - width) / 2; int offsetx = (originalWidth - width) / 2;
......
...@@ -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!