Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mr-julyedu
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
baiguangyao
mr-julyedu
Commits
29cc6c25
Commit
29cc6c25
authored
Jan 11, 2020
by
zhanghaozhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
海报
parent
90729eff
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
42 deletions
+14
-42
src/components/activity/give-courses/share-content/poster/poster.js
+14
-42
No files found.
src/components/activity/give-courses/share-content/poster/poster.js
View file @
29cc6c25
...
@@ -46,10 +46,9 @@ class Poster extends Component {
...
@@ -46,10 +46,9 @@ class Poster extends Component {
generatePoster
=
async
()
=>
{
generatePoster
=
async
()
=>
{
let
canvas
=
document
.
createElement
(
'canvas'
),
let
canvas
=
document
.
createElement
(
'canvas'
),
scale
=
window
.
devicePixelRatio
||
1
,
ctx
=
canvas
.
getContext
(
'2d'
),
ctx
=
canvas
.
getContext
(
'2d'
),
posterWidth
=
window
.
innerWidth
*
0.72
,
posterWidth
=
270
,
canvasWidth
=
posterWidth
*
scale
canvasWidth
=
540
const
{
backgroundUrl
,
avatar
,
username
,
redirectUrl
}
=
this
.
state
const
{
backgroundUrl
,
avatar
,
username
,
redirectUrl
}
=
this
.
state
...
@@ -60,51 +59,26 @@ class Poster extends Component {
...
@@ -60,51 +59,26 @@ class Poster extends Component {
canvas
.
width
=
canvasWidth
canvas
.
width
=
canvasWidth
canvas
.
height
=
canvasWidth
*
bg
.
height
/
bg
.
width
canvas
.
height
=
canvasWidth
*
bg
.
height
/
bg
.
width
console
.
log
(
scale
)
ctx
.
drawImage
(
bg
,
0
,
0
,
canvas
.
width
,
canvas
.
height
)
ctx
.
fillStyle
=
'#fff'
ctx
.
fillRect
(
0
,
0
,
canvas
.
width
,
canvas
.
height
)
ctx
.
fillStyle
=
'#000'
ctx
.
strokeRect
(
190
,
400
,
100
,
100
)
ctx
.
scale
(
scale
,
scale
)
ctx
.
strokeRect
(
190
,
400
,
100
,
100
)
document
.
body
.
appendChild
(
canvas
)
this
.
setState
({
poster
:
canvas
.
toDataURL
()
},
()
=>
{
const
{
savePoster
}
=
this
.
props
savePoster
&&
savePoster
(
this
.
state
.
poster
)
})
return
// ctx.drawImage(bg, 0, 0, canvas.width, canvas.height)
let
r
=
33
ctx
.
drawImage
(
bg
,
0
,
0
,
Math
.
round
(
+
canvas
.
style
.
width
.
slice
(
0
,
-
2
)),
Math
.
round
(
+
canvas
.
style
.
height
.
slice
(
0
,
-
2
)))
scale
=
1
let
r
=
16
*
scale
const
avatarImage
=
await
this
.
getImage
(
avatar
)
const
avatarImage
=
await
this
.
getImage
(
avatar
)
const
ax
=
20
*
scale
const
ax
=
40
const
ay
=
1
5
/
2
*
scale
const
ay
=
1
6
ctx
.
save
()
ctx
.
save
()
ctx
.
beginPath
()
ctx
.
beginPath
()
ctx
.
arc
(
r
+
ax
,
r
+
ay
,
r
,
0
,
Math
.
PI
*
2
)
ctx
.
arc
(
ax
+
r
,
ay
+
r
,
r
,
0
,
Math
.
PI
*
2
)
ctx
.
clip
()
ctx
.
clip
()
ctx
.
drawImage
(
avatarImage
,
ax
,
ay
,
2
*
r
,
2
*
r
)
ctx
.
drawImage
(
avatarImage
,
ax
,
ay
,
66
,
66
)
ctx
.
restore
()
ctx
.
restore
()
ctx
.
font
=
`
${
12
*
scale
}
px serif`
ctx
.
font
=
`
24
px serif`
ctx
.
fillStyle
=
'#fff'
ctx
.
fillStyle
=
'#fff'
ctx
.
fillText
(
username
,
2
*
r
+
ax
+
(
7
*
scale
),
22
*
scale
)
ctx
.
fillText
(
username
,
2
*
r
+
ax
+
10
,
ay
+
r
-
5
)
let
qrcode
=
await
this
.
getQRCodeCanvas
(
redirectUrl
,
scale
,
posterWidth
)
let
qrcode
=
await
this
.
getQRCodeCanvas
(
redirectUrl
,
posterWidth
)
// ctx.drawImage(qrcode, 192 * scale, 405 * scale, posterWidth * (100 / (window.innerWidth * 0.72)), posterWidth * (100 / (window.innerWidth * 0.72)))
ctx
.
drawImage
(
qrcode
,
380
,
796
,
140
,
140
)
ctx
.
drawImage
(
qrcode
,
190
*
scale
,
400
*
scale
,
70
,
70
)
// 540 384 810
// 894 636 1342
// ctx.drawImage(qrcode, 220, 450, 60, 60)
// document.body.appendChild(canvas)
this
.
setState
({
this
.
setState
({
...
@@ -127,9 +101,9 @@ class Poster extends Component {
...
@@ -127,9 +101,9 @@ class Poster extends Component {
})
})
}
}
getQRCodeCanvas
=
(
text
,
scale
,
posterWidth
)
=>
{
getQRCodeCanvas
=
(
text
,
posterWidth
)
=>
{
const
canvas
=
document
.
createElement
(
'canvas'
)
const
canvas
=
document
.
createElement
(
'canvas'
)
let
codeWidth
=
100
*
scale
,
codeHeight
=
100
*
scale
,
let
codeWidth
=
100
,
codeHeight
=
100
,
codeSize
=
posterWidth
*
(
100
/
(
window
.
innerWidth
*
0.72
))
codeSize
=
posterWidth
*
(
100
/
(
window
.
innerWidth
*
0.72
))
...
@@ -138,8 +112,6 @@ class Poster extends Component {
...
@@ -138,8 +112,6 @@ class Poster extends Component {
canvas
.
width
=
codeWidth
canvas
.
width
=
codeWidth
canvas
.
height
=
codeHeight
canvas
.
height
=
codeHeight
document
.
body
.
appendChild
(
canvas
)
return
QRCode
.
toCanvas
(
canvas
,
text
)
return
QRCode
.
toCanvas
(
canvas
,
text
)
}
}
...
...
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