-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtextimagegen.py
43 lines (28 loc) · 990 Bytes
/
textimagegen.py
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
from PIL import Image, ImageDraw,ImageFont
from discord.ext import commands
import discord
import random
import io
bot = commands.Bot(command_prefix=['?'],intents=discord.Intents.all())
BotToken='Put your bot token here'
@bot.command()
#trigger it by ' ?image [text] '
async def image(ctx,*,text):
#loads custom font
font=ImageFont.truetype('roboto.ttf',20)
#randomizes colors value but ''a" is set to 255
rgb=random.randint(0,255),random.randint(0,255),random.randint(0,255),255
#makes new image to draw
temp= Image.new('RGBA',(150,100),rgb)
#creates a drawing context
tempd=ImageDraw.Draw(temp)
#randomizes the colors for text's
rgb=random.randint(0,255),random.randint(0,255),random.randint(0,255),255
#applying the text and its font
tempd.text((5,5),text,font=font,fill=rgb)
#saves it to a buffer
buffer=io.BytesIO()
temp.save(buffer,"PNG")
#sends it to the chat
await ctx.send(file=discord.File(buffer,filename='image.png'))
bot.run(BotToken)