Commit 4c077489 authored by huangcb's avatar huangcb

调整水印文字默认大小为60

parent 96333f80
......@@ -3,6 +3,8 @@ package com.esv.freight.file.module.file.service.impl;
import com.esv.freight.file.module.file.form.WaterMarkForm;
import com.esv.freight.file.module.file.service.WatermarkService;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;
import javax.imageio.ImageIO;
......@@ -23,8 +25,12 @@ import java.util.Base64;
* @version:1.0
*/
@Service("watermarkService")
@RefreshScope
public class WatermarkServiceImpl implements WatermarkService {
@Value("${wartermarker.font.size: 60}")
private int WATERMARK_FONT_SIZE;
private static final String DEFAULT_FONT_PATH = "/font/迷你简大黑.TTF";
@Override
......@@ -39,7 +45,7 @@ public class WatermarkServiceImpl implements WatermarkService {
graphics2D.drawImage(image, 0, 0, imgWidth, imgHeight, null);
// 设置字体及颜色
Font font = getDefaultFont(DEFAULT_FONT_PATH, Font.PLAIN, 30);
Font font = getDefaultFont(DEFAULT_FONT_PATH, Font.PLAIN, WATERMARK_FONT_SIZE);
graphics2D.setFont(font);
Color color = new Color(255, 0, 0, 255);
graphics2D.setColor(color);
......@@ -49,7 +55,7 @@ public class WatermarkServiceImpl implements WatermarkService {
String[] texts = form.getText().split("\\|");
int length = texts.length;
for (int i = 0; i < length; i++) {
graphics2D.drawString(texts[i], 30, imgHeight - (30 * (length - i) ));
graphics2D.drawString(texts[i], 60, imgHeight - (WATERMARK_FONT_SIZE * (length - i) ));
}
graphics2D.dispose();
......
......@@ -59,4 +59,8 @@ baidu:
ocr:
app_id: 19433262
api_key: iXr2xpoGp3GPshCWkiW92W2G
secret_key: 6xzVIG8C3tQslR9zsM7q6gRYLNLc8ISB
\ No newline at end of file
secret_key: 6xzVIG8C3tQslR9zsM7q6gRYLNLc8ISB
#水印文字默认大小
wartermarker:
font:
size: 60
\ No newline at end of file
......@@ -59,4 +59,8 @@ baidu:
ocr:
app_id: 19433262
api_key: iXr2xpoGp3GPshCWkiW92W2G
secret_key: 6xzVIG8C3tQslR9zsM7q6gRYLNLc8ISB
\ No newline at end of file
secret_key: 6xzVIG8C3tQslR9zsM7q6gRYLNLc8ISB
#水印文字默认大小
wartermarker:
font:
size: 60
\ No newline at end of file
......@@ -3,6 +3,7 @@ package com.esv.freight.file.module.file.controller;
import com.alibaba.fastjson.JSONObject;
import com.esv.freight.file.BaseTestController;
import com.esv.freight.file.common.response.ECode;
import com.esv.freight.file.common.util.DateUtils;
import com.esv.freight.file.module.file.form.WaterMarkForm;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
......@@ -44,14 +45,14 @@ public class WatermarkControllerTest extends BaseTestController {
String url = "/upload/imageWithWatermark";
// 构造数据
String filepath = "D:\\test\\1366x768_107480_8.jpg";
String filepath = "D:\\test\\市府广场-1.jpg";
File file = new File(filepath);
InputStream input = new FileInputStream(file);
WaterMarkForm form = new WaterMarkForm();
form.setFileData(Base64.getEncoder().encodeToString(IOUtils.toByteArray(input)));
form.setFileName("图片水印合成.jpg");
form.setText("沈阳市和平区青年大街386号|2020/05/28 15:04");
form.setFileName("图片水印合成"+System.currentTimeMillis()+".jpg");
form.setText("沈阳市沈河区青年大街1号|" + DateUtils.getSysdateStr());
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
......
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