Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
file-service
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SuperHive
back-end
file-service
Commits
4c077489
Commit
4c077489
authored
May 29, 2020
by
huangcb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整水印文字默认大小为60
parent
96333f80
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
7 deletions
+22
-7
WatermarkServiceImpl.java
...t/file/module/file/service/impl/WatermarkServiceImpl.java
+8
-2
application-dev.yml
src/main/resources/application-dev.yml
+5
-1
application-test.yml
src/main/resources/application-test.yml
+5
-1
WatermarkControllerTest.java
.../file/module/file/controller/WatermarkControllerTest.java
+4
-3
No files found.
src/main/java/com/esv/freight/file/module/file/service/impl/WatermarkServiceImpl.java
View file @
4c077489
...
@@ -3,6 +3,8 @@ package com.esv.freight.file.module.file.service.impl;
...
@@ -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.form.WaterMarkForm
;
import
com.esv.freight.file.module.file.service.WatermarkService
;
import
com.esv.freight.file.module.file.service.WatermarkService
;
import
org.apache.commons.io.IOUtils
;
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
org.springframework.stereotype.Service
;
import
javax.imageio.ImageIO
;
import
javax.imageio.ImageIO
;
...
@@ -23,8 +25,12 @@ import java.util.Base64;
...
@@ -23,8 +25,12 @@ import java.util.Base64;
* @version:1.0
* @version:1.0
*/
*/
@Service
(
"watermarkService"
)
@Service
(
"watermarkService"
)
@RefreshScope
public
class
WatermarkServiceImpl
implements
WatermarkService
{
public
class
WatermarkServiceImpl
implements
WatermarkService
{
@Value
(
"${wartermarker.font.size: 60}"
)
private
int
WATERMARK_FONT_SIZE
;
private
static
final
String
DEFAULT_FONT_PATH
=
"/font/迷你简大黑.TTF"
;
private
static
final
String
DEFAULT_FONT_PATH
=
"/font/迷你简大黑.TTF"
;
@Override
@Override
...
@@ -39,7 +45,7 @@ public class WatermarkServiceImpl implements WatermarkService {
...
@@ -39,7 +45,7 @@ public class WatermarkServiceImpl implements WatermarkService {
graphics2D
.
drawImage
(
image
,
0
,
0
,
imgWidth
,
imgHeight
,
null
);
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
);
graphics2D
.
setFont
(
font
);
Color
color
=
new
Color
(
255
,
0
,
0
,
255
);
Color
color
=
new
Color
(
255
,
0
,
0
,
255
);
graphics2D
.
setColor
(
color
);
graphics2D
.
setColor
(
color
);
...
@@ -49,7 +55,7 @@ public class WatermarkServiceImpl implements WatermarkService {
...
@@ -49,7 +55,7 @@ public class WatermarkServiceImpl implements WatermarkService {
String
[]
texts
=
form
.
getText
().
split
(
"\\|"
);
String
[]
texts
=
form
.
getText
().
split
(
"\\|"
);
int
length
=
texts
.
length
;
int
length
=
texts
.
length
;
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
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
();
graphics2D
.
dispose
();
...
...
src/main/resources/application-dev.yml
View file @
4c077489
...
@@ -60,3 +60,7 @@ baidu:
...
@@ -60,3 +60,7 @@ baidu:
app_id
:
19433262
app_id
:
19433262
api_key
:
iXr2xpoGp3GPshCWkiW92W2G
api_key
:
iXr2xpoGp3GPshCWkiW92W2G
secret_key
:
6xzVIG8C3tQslR9zsM7q6gRYLNLc8ISB
secret_key
:
6xzVIG8C3tQslR9zsM7q6gRYLNLc8ISB
#水印文字默认大小
wartermarker
:
font
:
size
:
60
\ No newline at end of file
src/main/resources/application-test.yml
View file @
4c077489
...
@@ -60,3 +60,7 @@ baidu:
...
@@ -60,3 +60,7 @@ baidu:
app_id
:
19433262
app_id
:
19433262
api_key
:
iXr2xpoGp3GPshCWkiW92W2G
api_key
:
iXr2xpoGp3GPshCWkiW92W2G
secret_key
:
6xzVIG8C3tQslR9zsM7q6gRYLNLc8ISB
secret_key
:
6xzVIG8C3tQslR9zsM7q6gRYLNLc8ISB
#水印文字默认大小
wartermarker
:
font
:
size
:
60
\ No newline at end of file
src/test/java/com/esv/freight/file/module/file/controller/WatermarkControllerTest.java
View file @
4c077489
...
@@ -3,6 +3,7 @@ package com.esv.freight.file.module.file.controller;
...
@@ -3,6 +3,7 @@ package com.esv.freight.file.module.file.controller;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.esv.freight.file.BaseTestController
;
import
com.esv.freight.file.BaseTestController
;
import
com.esv.freight.file.common.response.ECode
;
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
com.esv.freight.file.module.file.form.WaterMarkForm
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.io.IOUtils
;
...
@@ -44,14 +45,14 @@ public class WatermarkControllerTest extends BaseTestController {
...
@@ -44,14 +45,14 @@ public class WatermarkControllerTest extends BaseTestController {
String
url
=
"/upload/imageWithWatermark"
;
String
url
=
"/upload/imageWithWatermark"
;
// 构造数据
// 构造数据
String
filepath
=
"D:\\test\\
1366x768_107480_8
.jpg"
;
String
filepath
=
"D:\\test\\
市府广场-1
.jpg"
;
File
file
=
new
File
(
filepath
);
File
file
=
new
File
(
filepath
);
InputStream
input
=
new
FileInputStream
(
file
);
InputStream
input
=
new
FileInputStream
(
file
);
WaterMarkForm
form
=
new
WaterMarkForm
();
WaterMarkForm
form
=
new
WaterMarkForm
();
form
.
setFileData
(
Base64
.
getEncoder
().
encodeToString
(
IOUtils
.
toByteArray
(
input
)));
form
.
setFileData
(
Base64
.
getEncoder
().
encodeToString
(
IOUtils
.
toByteArray
(
input
)));
form
.
setFileName
(
"图片水印合成.jpg"
);
form
.
setFileName
(
"图片水印合成
"
+
System
.
currentTimeMillis
()+
"
.jpg"
);
form
.
setText
(
"沈阳市
和平区青年大街386号|2020/05/28 15:04"
);
form
.
setText
(
"沈阳市
沈河区青年大街1号|"
+
DateUtils
.
getSysdateStr
()
);
MvcResult
mvcResult
=
this
.
getMockMvc
().
perform
(
MockMvcRequestBuilders
.
post
(
url
)
MvcResult
mvcResult
=
this
.
getMockMvc
().
perform
(
MockMvcRequestBuilders
.
post
(
url
)
.
contentType
(
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
.
contentType
(
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment