Пример #1
0
 async def banner(self, ctx, banner: str = None):
     """Adds a banner to the image welcomer, when added the image welcomer changes resolution to 2560 x 1440 so a banner that size would be ideal"""
     author = ctx.author
     server = ctx.guild
     data = r.table("welcomer").get(str(server.id))
     if not banner:
         if ctx.message.attachments:
             try:
                 banner = ctx.message.attachments[0].url
                 data.update({
                     "banner": banner
                 }).run(self.db, durability="soft")
                 return await ctx.send(
                     "Your banner for image welcomer has been set.")
             except:
                 pass
         data.update({"banner": None}).run(self.db, durability="soft")
         await ctx.send("Your banner for image welcomer has been reset.")
         return
     if ".webp" in banner:
         return await ctx.send("WEBP files are not supported :no_entry:")
     try:
         img.getImage(banner)
     except:
         return await ctx.send("Invalid image url :no_entry:")
     data.update({"banner": banner}).run(self.db, durability="soft")
     await ctx.send("Your banner for image welcomer has been set.")
Пример #2
0
    def image_welcomer(self, author, server):
        data = r.table("welcomer").get(str(server.id)).run(durability="soft")
        name = author.name

        def circlefy(image):
            size = (image.size[0] * 6, image.size[1] * 6)
            mask = Image.new('L', size, 0)
            draw = ImageDraw.Draw(mask)
            draw.ellipse((0, 0) + size, fill=255)
            mask = mask.resize(image.size)
            image.putalpha(mask)
            return image

        x = 440
        y = 410
        wel = 475
        z = 0
        if data["banner"]:
            try:
                background = img.getImage(data["banner"])
                background = background.resize((2560, 1440))
                trans = 200
            except:
                background = Image.new('RGBA', (2560, 630), (0, 0, 0, 0))
                trans = 200
                z += 5
                y -= 405
                x -= 405
                wel -= 405
        else:
            background = Image.new('RGBA', (2560, 630), (0, 0, 0, 0))
            trans = 200
            z += 5
            y -= 405
            x -= 405
            wel -= 405
        outline = Image.new("RGBA", (620, 620), (255, 255, 255))
        rectangle = Image.new("RGBA", (2560, 560), (0, 0, 0, trans))
        W, H = (2840, 560)
        outline = circlefy(outline)
        avatar = img.getImage(author.avatar_url)
        avatar = avatar.resize((600, 600))
        avatar = circlefy(avatar)
        background.paste(rectangle, (350 + z, x), rectangle)
        outline.paste(avatar, (10, 10), avatar)
        background.paste(outline, (z, y), outline)
        draw = ImageDraw.Draw(background)
        size = 200
        for i, somethingrandom in enumerate(name):
            if i >= 12 and i < 16:
                size -= 12
            elif i >= 16 and i < 23:
                size -= 7
            elif i >= 23 and i < 28:
                size -= 6
        if size < 0:
            return
        font = ImageFont.truetype("uni-sans.otf", 100)
        font2 = ImageFont.truetype("uni-sans.otf", size)
        w, h = font2.getsize(name)
        w2, h2 = font.getsize("Welcome")
        w3, h3 = font.getsize("#" + author.discriminator)
        draw.text(((W - w2) / 2, wel), "Welcome", (255, 255, 255), font=font)
        draw.text(((W - w) / 2, x + (H - h) / 2),
                  name, (255, 255, 255),
                  font=font2)
        draw.text(((W - w) / 2 + w, x + (H - h) / 2 +
                   (154 if size == 200 else h) - h3),
                  "#" + author.discriminator, (153, 170, 181),
                  font=font)
        temp = BytesIO()
        background.save(temp, "png")
        temp.seek(0)
        return discord.File(temp, "result.png")