Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
蒋秀川
/
miniProject
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 6512da16
authored
Sep 18, 2023
by
Tianqing Liu
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat: 增加水印功能
1 parent
df58ab59
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
13 deletions
h5/src/components/jPlayer/watermark.vue
h5/src/components/jPlayer/watermark.vue
View file @
6512da1
...
@@ -32,8 +32,9 @@ export default {
...
@@ -32,8 +32,9 @@ export default {
*/
*/
createCanvas
(
image
)
{
createCanvas
(
image
)
{
const
canvas
=
document
.
createElement
(
'canvas'
);
const
canvas
=
document
.
createElement
(
'canvas'
);
canvas
.
width
=
400
;
// 若不设置宽、高,无法渲染内容
canvas
.
height
=
300
;
canvas
.
width
=
this
.
width
;
canvas
.
height
=
this
.
height
;
// canvas.height = this.height - 40; // 40为底部工具条
// canvas.height = this.height - 40; // 40为底部工具条
canvas
.
className
=
'watermark'
;
canvas
.
className
=
'watermark'
;
console
.
log
(
'createCanvas'
,
canvas
);
console
.
log
(
'createCanvas'
,
canvas
);
...
@@ -48,17 +49,17 @@ export default {
...
@@ -48,17 +49,17 @@ export default {
// 绘制水印文本
// 绘制水印文本
ctx
.
font
=
'24px Arial'
;
ctx
.
font
=
'24px Arial'
;
ctx
.
fillStyle
=
'rgba(255, 255, 255, 0.
3
)'
;
ctx
.
fillStyle
=
'rgba(255, 255, 255, 0.
4
)'
;
// 定义水印内容
// 定义水印内容
const
watermarkText
=
this
.
text
;
const
watermarkText
=
this
.
text
;
// 定义水印间隔和边距
// 定义水印间隔和边距
// TODO: 未兼容移动端
// TODO: 未兼容移动端
const
watermarkIntervalX
=
8
0
;
// 水印之间的水平间隔
const
watermarkIntervalX
=
22
0
;
// 水印之间的水平间隔
const
watermarkIntervalY
=
8
0
;
// 水印之间的垂直间隔
const
watermarkIntervalY
=
26
0
;
// 水印之间的垂直间隔
const
watermarkMarginX
=
3
0
;
// 水印距离左边的边距
const
watermarkMarginX
=
5
0
;
// 水印距离左边的边距
const
watermarkMarginY
=
0
;
// 水印距离顶部的边距
const
watermarkMarginY
=
18
0
;
// 水印距离顶部的边距
// 循环绘制水印
// 循环绘制水印
for
(
let
x
=
watermarkMarginX
;
x
<
canvas
.
width
;
x
+=
watermarkIntervalX
)
{
for
(
let
x
=
watermarkMarginX
;
x
<
canvas
.
width
;
x
+=
watermarkIntervalX
)
{
...
@@ -87,10 +88,4 @@ export default {
...
@@ -87,10 +88,4 @@ export default {
</
script
>
</
script
>
<
style
lang=
"scss"
scoped
>
<
style
lang=
"scss"
scoped
>
.watermark-layer
{
::v-deep(canvas)
{
width
:
100%
;
height
:
100%
;
}
}
</
style
>
</
style
>
Write
Preview
Markdown
is supported
Attach a file
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 post a comment