PIL文本旋转(discord.py)

2024-09-29 01:38:20 发布

您现在位置:Python中文网/ 问答频道 /正文

@client.command()
async def shit(ctx, *, response=None):
    if response == None:
        await ctx.send("What am I gonna write lol")
    response = response.replace("(", "")
    response = response.replace(")", "")
    txt = Image.new('L', (500, 50))
    img = Image.open("img/shit-empty.jpg")
    draw = ImageDraw.Draw(img)
    w = txt.rotate(17.5, expand=1)

    font = ImageFont.truetype("Roboto-Bold.ttf", 50)
    # draw.text((x, y),"Sample Text",(r,g,b))
    draw.text((315, 845), f"{response}", font=font)
    img.paste(ImageOps.colorize(w, (0, 0, 0), (255,255,84)), (242,60), w)

    img.save('img/shit.jpg')

    await ctx.send(":poop: Eww")
    await ctx.send(file=discord.File("img/shit.jpg"))    

这是我的一个图像编辑命令的代码。它的工作原理很好,但它给出如下结果: enter image description here

我想旋转文字,因为它将与鞋子旋转相匹配,我如何才能做到这一点


Tags: textimagetxtclientnonesendimgresponse