简体   繁体   中英

Adding text to a image using PIL

So, I want the bot to send a welcome card with the user's profile picture & text saying " Welcome {user.name} ", but the text part isn't working. I have got no error in the console.

Here's my code:

from PIL import Image, ImageFilter, ImageFont, ImageDraw
from io import BytesIO

@client.event
async def on_member_join(member):

    wc = Image.open("wc.jpg")

    asset = member.avatar_url_as(size=128)
    data = BytesIO(await asset.read())
    pfp = Image.open(data)

    draw = ImageDraw.Draw(wc)
    font = ImageFont.truetype("Littlecandy.ttf", 24)
    
    pfp = pfp.resize((474,382))
    draw.text((549,284), f"{member.display_name}", (171, 5, 171), font=font)
    wc.paste(pfp, (727,209))
    wc.save("wcm.jpg")

    await client.get_channel(850634788633182218).send(file = discord.File('wcm.jpg'))

So, i have not got the answer but when i removed the RGB code that is this (171, 5, 171) than i tested it & it worked.

Here's my changed code:

from PIL import Image, ImageFilter, ImageFont, ImageDraw
from io import BytesIO

@client.comamnd()
async def on_member_join(member):

    wc2 = Image.open("wc2.jpg")

    asset = member.avatar_url_as(size=64)
    data = BytesIO(await asset.read())
    pfp = Image.open(data)

    draw = ImageDraw.Draw(wc2)
    font = ImageFont.truetype("BalsamiqSans-BoldItalic.ttf", 45)
    text = f"{member}" 

    pfp = pfp.resize((211,181))
    wc2.paste(pfp, (30,28))
    draw.text((26,235),text,font=font,fill='orange')
    wc2.save("wcm.jpg")

    await client.get_channel(850634788633182218).send(file = discord.File('wcm.jpg'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM