|
@@ -20,6 +20,12 @@ import java.awt.*;
|
|
import java.awt.image.BufferedImage;
|
|
import java.awt.image.BufferedImage;
|
|
import java.io.*;
|
|
import java.io.*;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.LinkedHashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.regex.Matcher;
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/attachmngs")
|
|
@RequestMapping("/attachmngs")
|
|
@@ -55,12 +61,37 @@ public class AttachmngsController {
|
|
System.out.println(date);
|
|
System.out.println(date);
|
|
|
|
|
|
// 水印
|
|
// 水印
|
|
- String address = mapUtils.pointsToLocationsAll(longitude + "," + latitude);
|
|
|
|
|
|
+ String address = "";
|
|
|
|
+ if (longitude != null && !"".equals(longitude) &&
|
|
|
|
+ latitude != null && !"".equals(latitude)) {
|
|
|
|
+ address = mapUtils.pointsToLocationsAll(longitude + "," + latitude);
|
|
|
|
+
|
|
|
|
+ String regex = "((?<province>[^省]+省|.+自治区)|上海|北京|天津|重庆)(?<city>[^市]+市|.+自治州)(?<county>[^县]+县|.+区|.+镇|.+局)?(?<town>[^区]+区|.+镇)?(?<village>.*)";
|
|
|
|
+ Matcher m = Pattern.compile(regex).matcher(address);
|
|
|
|
+ String province = null, city = null, county = null, town = null, village = null;
|
|
|
|
+ List<Map<String, String>> table = new ArrayList<>();
|
|
|
|
+ Map<String, String> row = null;
|
|
|
|
+ while (m.find()) {
|
|
|
|
+ row = new LinkedHashMap<>();
|
|
|
|
+ province = m.group("province");
|
|
|
|
+ row.put("province", province == null ? "" : province.trim());
|
|
|
|
+ city = m.group("city");
|
|
|
|
+ row.put("city", city == null ? "" : city.trim());
|
|
|
|
+ county = m.group("county");
|
|
|
|
+ row.put("county", county == null ? "" : county.trim());
|
|
|
|
+ town = m.group("town");
|
|
|
|
+ row.put("town", town == null ? "" : town.trim());
|
|
|
|
+ village = m.group("village");
|
|
|
|
+ row.put("village", village == null ? "" : village.trim());
|
|
|
|
+ table.add(row);
|
|
|
|
+ }
|
|
|
|
+ address = province + city + county;
|
|
|
|
+ }
|
|
String watermark = address + "||" + date + "||" + carRegNo;
|
|
String watermark = address + "||" + date + "||" + carRegNo;
|
|
File file2 = AddWatermarkUtil.transferToFile(file);
|
|
File file2 = AddWatermarkUtil.transferToFile(file);
|
|
|
|
|
|
System.out.println("水印前大小:" + file2.length() / 1024);
|
|
System.out.println("水印前大小:" + file2.length() / 1024);
|
|
- AddWatermarkUtil.waterPress(file2, file2, Color.WHITE, 48, watermark);
|
|
|
|
|
|
+ AddWatermarkUtil.waterPress(file2, file2, Color.WHITE, 48, watermark);
|
|
// AddWatermarkUtil.addWaterMark(file2, file2, Color.DARK_GRAY, 48, watermark);
|
|
// AddWatermarkUtil.addWaterMark(file2, file2, Color.DARK_GRAY, 48, watermark);
|
|
|
|
|
|
// MultipartFile multipartFile = AddWatermarkUtil.fileToTransfer(file2);
|
|
// MultipartFile multipartFile = AddWatermarkUtil.fileToTransfer(file2);
|
|
@@ -68,12 +99,12 @@ public class AttachmngsController {
|
|
// ByteArrayOutputStream f = new ByteArrayOutputStream();
|
|
// ByteArrayOutputStream f = new ByteArrayOutputStream();
|
|
String fileName = file2.getName();
|
|
String fileName = file2.getName();
|
|
// if (file2.length() > 50 * 1024) {
|
|
// if (file2.length() > 50 * 1024) {
|
|
- // 压缩
|
|
|
|
|
|
+ // 压缩
|
|
Thumbnails.of(file2)
|
|
Thumbnails.of(file2)
|
|
- .scale(0.6f) //图片大小(长宽)压缩比例 从0-1,1表示原图
|
|
|
|
- .toFile("/usr/local/project/DaoHe/imgFiles/" + fileName + ".jpg");
|
|
|
|
- File file1 = new File("/usr/local/project/DaoHe/imgFiles/" + fileName + ".jpg");
|
|
|
|
- System.out.println("压缩中大小:" + file1.length() / 1024);
|
|
|
|
|
|
+ .scale(0.6f) //图片大小(长宽)压缩比例 从0-1,1表示原图
|
|
|
|
+ .toFile("/usr/local/project/DaoHe/imgFiles/" + fileName + ".jpg");
|
|
|
|
+ File file1 = new File("/usr/local/project/DaoHe/imgFiles/" + fileName + ".jpg");
|
|
|
|
+ System.out.println("压缩中大小:" + file1.length() / 1024);
|
|
// }
|
|
// }
|
|
// compressPicCycle(file2, 50L, 0.5);
|
|
// compressPicCycle(file2, 50L, 0.5);
|
|
System.out.println("压缩完成大小:" + file1.length() / 1024);
|
|
System.out.println("压缩完成大小:" + file1.length() / 1024);
|
|
@@ -115,8 +146,8 @@ public class AttachmngsController {
|
|
int srcHeight = bim.getHeight();
|
|
int srcHeight = bim.getHeight();
|
|
int destWidth = new BigDecimal(srcWidth).multiply(new BigDecimal(accuracy)).intValue();
|
|
int destWidth = new BigDecimal(srcWidth).multiply(new BigDecimal(accuracy)).intValue();
|
|
int destHeight = new BigDecimal(srcHeight).multiply(new BigDecimal(accuracy)).intValue();
|
|
int destHeight = new BigDecimal(srcHeight).multiply(new BigDecimal(accuracy)).intValue();
|
|
- Thumbnails.of(desPath).size(destWidth,destHeight).outputQuality(accuracy).toFile(desPath);
|
|
|
|
- compressPicCycle(desPath,desFileSize,accuracy);
|
|
|
|
|
|
+ Thumbnails.of(desPath).size(destWidth, destHeight).outputQuality(accuracy).toFile(desPath);
|
|
|
|
+ compressPicCycle(desPath, desFileSize, accuracy);
|
|
System.out.println("压缩中大小:" + desPath.length() / 1024);
|
|
System.out.println("压缩中大小:" + desPath.length() / 1024);
|
|
}
|
|
}
|
|
|
|
|