[英]Adding text to a image using PIL
所以,我希望機器人發送一張帶有用戶個人資料圖片和文字的歡迎卡,上面寫着“歡迎 {user.name}”,但文字部分不起作用。 我在控制台中沒有錯誤。
這是我的代碼:
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'))
所以,我沒有得到答案,但是當我刪除了這個(171, 5, 171)
的 RGB 代碼時,我對其進行了測試並且它有效。
這是我更改的代碼:
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'))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.