generators.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:Tuxedo 作者: ClarityMoe 项目源码 文件源码
def invert(self, ctx, target):
        """ Ever wanted to see the stuff of nightmares? """
        try:
            member = await commands.MemberConverter().convert(ctx, target)
            url = member.avatar_url
        except:
            url = target

        url = url.replace("gif", "png").strip("<>")
        m = await ctx.send("pls wait am generating")

        try:
            b = BytesIO()
            async with aiohttp.ClientSession() as session:
                async with session.get(url) as r:
                    img = Image.open(BytesIO(await r.read()))
                    bio = BytesIO()

                    if (img.mode == 'RGBA'):
                        r,g,b,a = img.split()
                        rgb_image = Image.merge('RGB', (r,g,b))
                        inverted = ImageOps.invert(rgb_image)
                        r,g,b = inverted.split()
                        img = Image.merge('RGBA', (r,g,b,a))
                    else:
                        img = ImageOps.invert(img)

                    img.save(bio, "PNG")
                    bio.seek(0)
                    await ctx.send(file=discord.File(bio, filename="invert.png"))
                    await m.delete()
        except Exception as e:
            print(e)
            await m.edit(content="Unable to generate image. Provide a mention or valid URL.")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号