/**
* 縦の比率が小さい場合
* @param im
* @param prmFont
* @param comment
* @return
*/
private BufferedImage cropImageShortestHeght(BufferedImage im,Font prmFont,String comment){
//元画像のサイズを抽出
double souceHeight = im.getHeight();
double souceWidth = im.getWidth();
//縮小比率
double reductionRatio = resizeH/souceHeight;
//左右の差を出す
double horizontalLength = souceWidth * reductionRatio;
double horizontalDiff = resizeW - horizontalLength;
double distance = horizontalDiff/2;
BufferedImage resizeImage = null;
try{
//出力用の背景を作成する
resizeImage = new BufferedImage((int)resizeW,(int)resizeH, BufferedImage.TYPE_INT_RGB);
//元画像のサイズを変更する
Graphics2D image = im.createGraphics();
image.scale(reductionRatio, reductionRatio);
//画像を背景に移す
Graphics2D g = resizeImage.createGraphics();
g.drawImage(im, (int)distance, 0, (int)(im.getWidth() * reductionRatio),(int)(im.getHeight() * reductionRatio), this);
g.setFont(prmFont);
g.setColor(Color.white);
comment = comment.replaceAll("<br />", "");
comment = comment.replaceAll("<br/>", "");
comment = comment.replaceAll("<br />", "");
if(comment.length() < 30){
g.drawString(comment, 40, 60);
}else{
int length = comment.length() / 30;
int backNumber = 0;
int endcount = 0;
int y = 0;
for(int i = 1; i <= length; i++){
endcount = 30 * i - 1;
y = 30 * i + 30;
String test = comment.substring(backNumber,endcount);
g.drawString(test, 80, y);
backNumber = endcount;
}
String test = comment.substring(backNumber,comment.length());
g.drawString(test, 80, y + 30);
}
g.dispose();
}catch (NullPointerException e) {
System.out.println("イメージがnull");
}
return resizeImage;
}
/**
* 縦横比率が同じ
* @param im
* @param prmFont
* @param comment
* @return
*/
private BufferedImage cropImageSameRatios(BufferedImage im,Font prmFont,String comment){
//元画像のサイズを抽出
double souceHeight = im.getHeight();
double souceWidth = im.getWidth();
//縮小比率
double reductionRatio = resizeW/souceWidth;
//左右の差を出す
double verticalLength = souceHeight * reductionRatio;
double verticalDiff = resizeH - verticalLength;
double distance = verticalDiff/2;
BufferedImage resizeImage = null;
try{
//出力用の背景を作成する
resizeImage = new BufferedImage((int)resizeW,(int)resizeH, BufferedImage.TYPE_INT_RGB);
//元画像のサイズを変更する
Graphics2D image = im.createGraphics();
image.scale(reductionRatio, reductionRatio);
//画像を背景に移す
Graphics2D g = resizeImage.createGraphics();
g.drawImage(im, 0, 0, (int)(im.getWidth() * reductionRatio),(int)(im.getHeight() * reductionRatio), this);
g.setFont(prmFont);
g.setColor(Color.white);
comment = comment.replaceAll("<br />", "");
comment = comment.replaceAll("<br/>", "");
comment = comment.replaceAll("<br />", "");
if(comment.length() < 30){
g.drawString(comment, 40, 60);
}else{
int length = comment.length() / 30;
int backNumber = 0;
int endcount = 0;
int y = 0;
for(int i = 1; i <= length; i++){
endcount = 30 * i - 1;
y = 30 * i + 30;
String test = comment.substring(backNumber,endcount);
g.drawString(test, 80, y);
backNumber = endcount;
}
String test = comment.substring(backNumber,comment.length());
g.drawString(test, 80, y + 30);
}
g.dispose();
}catch (NullPointerException e) {
System.out.println("イメージがnull");
}
return resizeImage;
}