【发布时间】:2021-10-07 02:33:00
【问题描述】:
我做了一个向图像添加文本的命令。但问题是,有时如果有人输入长消息,文本就会离开屏幕。我该如何解决这个问题?
@bot.command()
async def Picture1(ctx,*,message=None):
member = ctx.author
if message ==None:
await ctx.send("You have to put a message in idiot")
return
text1 = str(member)
print(text1)
# get an image
base = Image.open(r"C:\Users\User\Pictures\Picture.png").convert("RGBA")
# make a blank image for the text, initialized to transparent text color
txt = Image.new("RGBA", base.size, (255, 255, 255, 0))
# get a font
fnt = ImageFont.truetype(
r"C:\Users\User\fonts\courbi.ttf", 40)
# get a drawing context
d = ImageDraw.Draw(txt)
# draw text, half opacity
d.text((21, 70), "'" + message + "'", font=fnt,
fill=(255, 255, 255, 128))
# draw text, full opacity
d.text((10, 213), "-" + text1, font=fnt, fill=(255, 255, 255, 255))
out = Image.alpha_composite(base, txt)
out.save("picutre1.png", format="png")
print(out.save)
await ctx.send(file=discord.File("quote.png"))
【问题讨论】:
标签: python discord.py python-imaging-library