Commit e9fceca0 by songyinghui

feat: 新版图片合成

parent f445e3c8
......@@ -196,6 +196,11 @@
<artifactId>gic-order-api</artifactId>
<version>${gic-order-api}</version>
</dependency>
<dependency>
<groupId>com.freewayso</groupId>
<artifactId>image-combiner</artifactId>
<version>2.6.3</version>
</dependency>
</dependencies>
<build>
......
package com.gic.haoban.manage.service.util;
import com.alibaba.fastjson.JSON;
import com.freewayso.image.combiner.ImageCombiner;
import com.freewayso.image.combiner.enums.OutputFormat;
import com.freewayso.image.combiner.enums.ZoomMode;
import com.gic.thirdparty.cloudfile.CloudFileUtil;
import com.gic.thirdparty.cloudfile.enums.CloudFileBusinessOptEnum;
import com.gic.thirdparty.cloudfile.enums.CloudFileTypeEnum;
......@@ -104,17 +107,6 @@ public class DrawImageUtils {
return null;
}
static InputStream inputStream = null;
static {
try {
URL url = new URL("https://gicinner-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-80819999f96f448d9fcccb5ac86e6c37.png");
inputStream = url.openStream();
} catch (Exception ex) {
}
}
/***
* 二维码合成
......@@ -185,6 +177,46 @@ public class DrawImageUtils {
return url;
}
public static String addWaterNew(String factoryCode, String url, String qrCodeUrl) {
// 读取原图片信息
//文件转化为图片
try {
long startTime = System.currentTimeMillis();
ImageCombiner imageCombiner = new ImageCombiner(url, OutputFormat.JPG);
BufferedImage combinedImage = imageCombiner.getCombinedImage();
int srcImgWidth = combinedImage.getWidth(null);
int srcImgHeight = combinedImage.getHeight(null);
log.info("图片宽度:{}, 图片高度:{}", srcImgHeight, srcImgHeight);
if (srcImgHeight > 2000) {
log.info("原图片高度超过2000 高度:{}, 等比压缩", srcImgHeight);
// 按高度等比压缩
int tempWidth = BigDecimal.valueOf(srcImgWidth)
.multiply(BigDecimal.valueOf(2000).divide(BigDecimal.valueOf(srcImgHeight), 2, RoundingMode.HALF_DOWN))
.intValue();
log.info("压缩后的宽:{}", tempWidth);
srcImgHeight = 2000;
srcImgWidth = tempWidth;
imageCombiner = new ImageCombiner(combinedImage, tempWidth, 2000, ZoomMode.Height, OutputFormat.JPG);
}
// 计算二维码宽度
int qrCodeWidthTemp = srcImgWidth * 136 / 750;
imageCombiner.addImageElement(qrCodeUrl, srcImgWidth - (qrCodeWidthTemp + 20), srcImgHeight - (qrCodeWidthTemp + 20), qrCodeWidthTemp, qrCodeWidthTemp, ZoomMode.Height);
imageCombiner.combine();
InputStream combinedImageStream = imageCombiner.getCombinedImageStream();
log.info("合成之后的大小 {}", combinedImageStream.available());
CloudFileInfo cloudFileInfo = CloudFileUtil.uploadFile(combinedImageStream, "jpg", CloudFileTypeEnum.IMAGE, factoryCode, CloudFileBusinessOptEnum.HAOBAN_COMMON);
log.info("上传图片结果:{}", JSON.toJSONString(cloudFileInfo));
long endTime = System.currentTimeMillis();
log.info("合成图片耗时 {} 秒", (endTime - startTime) / 1000);
if (cloudFileInfo != null) {
return cloudFileInfo.getOrgFileUrl();
}
}catch (Exception ex) {
log.info("处理图片发生异常", ex);
}
return url;
}
public static BufferedImage resize(Image img, int h, int w, boolean clip) throws IOException {
//参数是TYPE_3BYTE_BGR时,图片最清晰!
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
......@@ -204,16 +236,12 @@ public class DrawImageUtils {
}
public static void main(String[] args) throws Exception {
try {
URL url = new URL("https://gicinner-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-80819999f96f448d9fcccb5ac86e6c37.png");
inputStream = url.openStream();
} catch (Exception ex) {
}
String qrcodeUrl = "https://gicinner-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-80819999f96f448d9fcccb5ac86e6c37.png";
String url = "https://jhdm-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-7c3bc8061ffb4e2694c0e288a1ce176b.jpeg?imageView2/format/jpg/q/50";
//String url = "https://newdmwltest-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-bd89447576b5438d8045def2da2c4c0f.jpg?imageView2/format/jpg/q/50";
System.setProperty("gic.module.name", "haoban-manage3-service");
DrawImageUtils.addWater("jhdm", url, inputStream);
System.out.println(DrawImageUtils.addWaterNew("jhdm", url, qrcodeUrl));
// Random random = new Random();
// String url = DrawImageUtils.drawImage("jhdm", Math.abs(random.nextInt(1000)) + "",
// Math.abs(random.nextInt(1000)) + "万", DrawBkgImg.AREA_MONTH_BKG);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment