-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateimage.js
64 lines (49 loc) · 1.69 KB
/
generateimage.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const Canvas = require("canvas")
const Discord = require("discord.js")
const background = "https://i.imgur.com/sKV54PO.jpeg"
const dim = {
height: 675,
width: 1200,
margin: 50
}
const av = {
size: 256,
x: 480,
y: 170
}
const generateImage = async (member) => {
let username = member.user.username
let discrim = member.user.discriminator
let avatarURL = member.user.displayAvatarURL({format: "png", dynamic: false, size: av.size})
const canvas = Canvas.createCanvas(dim.width, dim.height)
const ctx = canvas.getContext("2d")
//draw in the background
const backimg = await Canvas.loadImage(background)
ctx.drawImage(backimg, 0, 0)
//draw black tinted box
ctx.fillStyle = "rgba(0,0,0,0.8)"
ctx.fillRect(dim.margin, dim.margin, dim.width - 2 * dim.margin, dim.height - 2 *dim.margin)
const avimg = await Canvas.loadImage(avatarURL)
ctx.save()
ctx.beginPath()
ctx.arc(av.x = av.size / 2, av.y + av.size /2, av.size / 2, 0, Math.PI * 2, true)
ctx.closePath()
ctx.clip()
ctx.drawImage(avimg, av.x, av.y)
ctx.restore()
//write in text
ctx.fillStyle = "white"
ctx.textAlign = "center"
// draw in Welcome
ctx.font = "50px Roman"
ctx.fillText("Welcome", dim.width/2, dim.margin + 70)
// draw in the username
ctx.font = "60px Roman"
ctx.fillText(username + discrim, dim.width/2, dim.height - dim.margin - 125)
// draw in to the server
ctx.font = "40pc Roman"
ctx.fillText('to the server', dim.width / 2, dim.height - dim.margin - 50)
const attachament = new Discord.MessageAttachment(canvas.toBuffer(), "welcome.png")
return attachament
}
module.exports = generateImage