|
@@ -10,11 +10,13 @@ import java.awt.image.BufferedImage;
|
|
|
import java.io.File;
|
|
|
import java.util.Date;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
|
import com.ssj.bean.sys.poster.domain.PosterActivityJoin;
|
|
|
import com.ssj.dao.sys.poster.dao.*;
|
|
|
+import com.ssj.framework.weixin.news.bean.Template;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -97,22 +99,24 @@ public class PosterJoinServiceImpl extends BaseServiceImpl<PosterJoin, String> i
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
PosterTemplate posterTemplate=new PosterTemplate();
|
|
|
- posterTemplate.setBackImg("1.png");
|
|
|
- posterTemplate.setAddressPosition("856");
|
|
|
- posterTemplate.setNumberPosition("856");
|
|
|
- posterTemplate.setLogoPosition("30;34");
|
|
|
- posterTemplate.setQrcodePosition1("123;123;77;505");
|
|
|
- posterTemplate.setQrcodePosition2("123;123;300;505");
|
|
|
+ posterTemplate.setBackImg("3-1.png");
|
|
|
+ posterTemplate.setAddressPosition("307;1622;150");
|
|
|
+ posterTemplate.setNumberPosition("307;1580;150");
|
|
|
+ posterTemplate.setLogoPosition("64;63");
|
|
|
+ posterTemplate.setQrcodePosition1("155;155;110;1511");
|
|
|
+ posterTemplate.setFontColor("59;63;66;1");
|
|
|
+ posterTemplate.setFontSize(28);
|
|
|
+ posterTemplate.setBackLength(1000);
|
|
|
+ //posterTemplate.setQrcodePosition2("123;123;300;505");
|
|
|
|
|
|
PosterJoin posterJoin=new PosterJoin();
|
|
|
- posterJoin.setLogoImg("2.png");
|
|
|
- posterJoin.setQrcodeImg1("3.png");
|
|
|
- posterJoin.setQrcodeImg2("3.png");
|
|
|
+ posterJoin.setLogoImg("logo.png");
|
|
|
+ posterJoin.setQrcodeImg1("qr1.png");
|
|
|
posterJoin.setName("活动");
|
|
|
- posterJoin.setPhone("联系人:吴老师 13265096161");
|
|
|
- posterJoin.setAddress("地址:佛山市南海区桂城融和路号号中铁建水岸花园号号号铺铺铺");//33个字
|
|
|
+ posterJoin.setPhone("吴老师 13265096161");
|
|
|
+ posterJoin.setAddress("广州市海珠区罗马家园中盛路拜庭二期04-06 商铺");
|
|
|
|
|
|
- String url=runGeneratePosterImg(posterTemplate, posterJoin,"");
|
|
|
+ String url=runGeneratePosterImg(posterTemplate, posterJoin,"测试");
|
|
|
System.out.println(url);
|
|
|
|
|
|
|
|
@@ -138,6 +142,13 @@ public class PosterJoinServiceImpl extends BaseServiceImpl<PosterJoin, String> i
|
|
|
String[] logoPositions=posterTemplate.getLogoPosition().split(";");
|
|
|
BufferedImage logoImage = ImageIO.read(new File(savePath+posterJoin.getLogoImg()));
|
|
|
BufferedImage target_template=ImgBean.modifyImagetogeter(logoImage, source_template,Integer.parseInt(logoPositions[0]),Integer.parseInt(logoPositions[1]));
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(posterTemplate.getLogoPosition2())){
|
|
|
+ //合成logo2
|
|
|
+ logoImage = ImageIO.read(new File(savePath+posterJoin.getLogoImg2()));
|
|
|
+ target_template=ImgBean.modifyImagetogeter(logoImage, target_template,Integer.parseInt(logoPositions[2]),Integer.parseInt(logoPositions[3]));
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
//合成二维码1
|
|
|
String[] qrcodePositions=posterTemplate.getQrcodePosition1().split(";");
|
|
@@ -181,21 +192,46 @@ public class PosterJoinServiceImpl extends BaseServiceImpl<PosterJoin, String> i
|
|
|
File code1File2 = new File(code);
|
|
|
code1File2.delete();
|
|
|
}
|
|
|
-
|
|
|
- //合成联系人
|
|
|
+
|
|
|
+ //设置字体大小
|
|
|
+ int fontSize = posterTemplate.getFontSize();
|
|
|
+ Font font = new Font("黑体", Font.BOLD, fontSize);
|
|
|
+
|
|
|
+ //String[] colorRgba = posterTemplate.getFontColor().split(";");
|
|
|
+ //Color color = new Color(Integer.parseInt(colorRgba[0]),Integer.parseInt(colorRgba[1]) ,Integer.parseInt(colorRgba[2]) ,Integer.parseInt(colorRgba[3]));
|
|
|
+ Color color = new Color(0,0,0);
|
|
|
+ //合成联系人 x;y
|
|
|
String[] numberPositions=posterTemplate.getNumberPosition().split(";");
|
|
|
- ImgBean.modifyImage(target_template,"联系人:"+posterJoin.getPhone(),115,Integer.parseInt(numberPositions[0]),new Color(240,240,240),new Font("黑体", Font.PLAIN, 19));
|
|
|
+ String phone = "联系人:"+posterJoin.getPhone();
|
|
|
+ int leftX = Integer.parseInt(numberPositions[0]);
|
|
|
+ int topY = Integer.parseInt(numberPositions[1]);
|
|
|
+ if(posterJoin.getPhone().contains("/n")){
|
|
|
+ String[] phones = phone.split("/n");
|
|
|
+ ImgBean.modifyImage(target_template,phones[0],leftX,topY,color,font);
|
|
|
+ phone = phones[1];
|
|
|
+ leftX = leftX+fontSize*4;
|
|
|
+ topY = topY+fontSize+2;
|
|
|
+ }
|
|
|
+ //ImgBean.modifyImage(target_template,"联系人:"+posterJoin.getPhone(),leftX,topY,new Color(240,240,240),new Font("黑体", Font.PLAIN, 28));
|
|
|
+ ImgBean.modifyImage(target_template,phone,leftX,topY,color,font);
|
|
|
|
|
|
- //合成地址
|
|
|
+ //合成地址 x;y;rx
|
|
|
//长500的,最多33个字,500/33=15px (33-Address.le)/2=?
|
|
|
String[] addressPositions=posterTemplate.getAddressPosition().split(";");
|
|
|
- int left=0;
|
|
|
- if(posterJoin.getAddress().length()<33) {
|
|
|
- left=(33-posterJoin.getAddress().length())/2*15;
|
|
|
- }
|
|
|
- ImgBean.modifyImage(target_template,"地址:"+posterJoin.getAddress(),left,Integer.parseInt(addressPositions[0]),new Color(220,220,220),new Font("黑体", Font.PLAIN, 15));
|
|
|
+ int leftAddress = Integer.parseInt(addressPositions[0]);
|
|
|
+ int topAddress = Integer.parseInt(addressPositions[1]);
|
|
|
+ int rightAddress = Integer.parseInt(addressPositions[2]);
|
|
|
+ int maxNum = (posterTemplate.getBackLength()-leftAddress-rightAddress)/fontSize;
|
|
|
+ String address = "地址:"+posterJoin.getAddress();
|
|
|
+ //换行
|
|
|
+ if(address.length()>maxNum){
|
|
|
+ ImgBean.modifyImage(target_template,address.substring(0,maxNum),leftAddress,topAddress,color,font);
|
|
|
+ address = address.substring(maxNum);
|
|
|
+ leftAddress = leftAddress+fontSize*3;
|
|
|
+ topAddress = topAddress+fontSize+2;
|
|
|
+ }
|
|
|
+ ImgBean.modifyImage(target_template,address,leftAddress,topAddress,color,font);
|
|
|
|
|
|
- //System.out.println("step--生成海报-->ImgBean.writeImageLocal--"+target_path);
|
|
|
//生成海报
|
|
|
ImgBean.writeImageLocal(target_path, source_template);
|
|
|
|