diff options
author | 2019-08-03 23:19:40 +0100 | |
---|---|---|
committer | 2019-08-03 23:19:40 +0100 | |
commit | 1304806244caaba179449053b9d83985e5e44c4f (patch) | |
tree | 0fc98c55ff1d8a712d39a186a1ccea430403ac27 | |
parent | aghhh I suck at programming (diff) |
8bitify
-rw-r--r-- | bot/seasons/evergreen/8bitify.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/bot/seasons/evergreen/8bitify.py b/bot/seasons/evergreen/8bitify.py new file mode 100644 index 00000000..ae732fe5 --- /dev/null +++ b/bot/seasons/evergreen/8bitify.py @@ -0,0 +1,54 @@ +from io import BytesIO + +import discord +from PIL import Image +from discord.ext import commands + + +class EightBitify(commands.Cog): + """Make your avatar 8bit!""" + + def __init__(self, bot): + self.bot = bot + + @staticmethod + def pixelate(image: Image): + """Takes an image and pixelates it""" + return image.resize((32, 32)).resize((1024, 1024)) + + @staticmethod + def quantize(image: Image): + """Reduces colour palette to 256 colours""" + return image.quantize(colors=32) + + @commands.command(name="8bitify") + async def eightbit_command(self, ctx): + """Pixelates your avatar and changes the palette to an 8bit one""" + async with ctx.typing(): + image_bytes = await ctx.author.avatar_url.read() + avatar = Image.open(BytesIO(image_bytes)) + avatar = avatar.convert("RGBA").resize((1024, 1024)) + + eightbit = self.pixelate(avatar) + eightbit = self.quantize(eightbit) + + bufferedio = BytesIO() + eightbit.save(bufferedio, format="PNG") + bufferedio.seek(0) + + file = discord.File(bufferedio, filename="8bitavatar.png") + + embed = discord.Embed( + name="You're 8-bit avatar", + description='Here is your avatar. I think it looks all cool and "retro"' + ) + + embed.set_image(url="attachment://8bitavatar.png") + embed.set_footer(text=f"Made by {ctx.author.display_name}", icon_url=ctx.author.avatar_url) + + await ctx.send(file=file, embed=embed) + + +def setup(bot): + """Cog load.""" + bot.add_cog(EightBitify(bot)) |