-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcertificate.js
32 lines (27 loc) · 933 Bytes
/
certificate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*..................certificate.............*/
var canvas = document.getElementById('canvas')
var ctx = canvas.getContext('2d')
var nameInput = document.getElementById('name')
var downloadBtn = document.getElementById('download-btn')
var image = new Image()
image.crossOrigin="anonymous";
image.src = 'certificate2.png'
image.onload = function () {
drawImage()
}
function drawImage() {
// ctx.clearRect(0, 0, canvas.width, canvas.height)
ctx.drawImage(image, 0, 0, canvas.width, canvas.height)
ctx.font = '30px monotype corsiva'
ctx.fillStyle = '#14213d'
ctx.fillText(nameInput.value, 240, 175)
ctx.textAlign = 'center'
}
nameInput.addEventListener('input', function () {
drawImage()
})
downloadBtn.addEventListener('click', function () {
downloadBtn.href = canvas.toDataURL('image/png')
downloadBtn.download = 'Certificate - ' + nameInput.value
window.location.href="index.html";
})