From accaef04065ff8ca2a52d05f18dabf4d023cb3dc Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Thu, 21 Sep 2023 19:25:01 +0100 Subject: [PATCH] Extremify jimmy --- assets/extreme.png | Bin 0 -> 2044 bytes cogs/extremism.py | 72 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 assets/extreme.png create mode 100644 cogs/extremism.py diff --git a/assets/extreme.png b/assets/extreme.png new file mode 100644 index 0000000000000000000000000000000000000000..902602f33edb9454fdb4901b811cd3b9eea17b31 GIT binary patch literal 2044 zcmcgtdo+}37$0WLkdez)qg2zza#TlylL>_oq9_$%CSOz{%Y>zp%jCH1#@g0xG;S5T zxK$`p`DBe;hcH6MIv6y@U^LTY#_T(t{d51=v+eF5-}#;Ad4J#UdB6Aheb4*jQCCN` zHJjET5D2wHPWJ8ygo3vGQAUGI^3SuW2n442ko|!Zm-FUEjDzz6##l`0-JrXj1>3v)`_J@_<|JFivg(adCy*=mdrD{ray*>ecD-_ZTv)n5I zq-Tq-raQrJ9VR&3CQ5h|;r-{Uxm8hMcjt!c))BRfGELMOIMvh9$DFUMW{a47%L)wQ^soO68`Hzr&hh^3{xbePYfr= z9|Zlx)iSpc`19fm?>F~bp=xp+_5Kx?eYH*h6d1Z6gYdX0YQo2PI*X6-!pm>GlydHZ zj{5Mz`?nLg(`O9Nom$bjI9V)I2wF-({XeJpH@hW2?2{vwblLrwq^QTw#v~6i!#q|t zbNvW&98p`0CT*l)m^~!v=$%}|2jM5lsf;d(PHaWvtk)K5eZJhw4GH5cT&=ny8A_;6 z1YeH4M4eLU{Pk&+SvoLZRV`D2yq(}eYn7WekQZ(I)rRz8{)gr%R+M zVV_f?6a{Dy;S~j&5{%yCsbV|;Q(Zn0`&{F9w0}<`tyVqt04|JWPB6nM`wXfvIEp(T zWfQgOs^yGfB@mTWdr%kcA|82jwX_qAPCQzxTXg`pV^*rhC{q2nY(YSi@0UHJ8qe6q z#9)Dv_nlBV!MoU#2l<^?q8{`IG7ttNKr?eWOen$yppSkYK}{;}Q8_D0%K-9+heaf}eP4 zVYzpA;e2fD4iie%Lzy_FMfa^_aRy}PCAP;`cEQrXgHU_No4oD<2_-r}a9`*ZztVdP zCPj-IAB>(Y!g%9o^`L9kyGuv|Ru~Gg0-JgS{rPql)zEC?Od<=-83wIBev=v!6a)P< zj*a+JIq@Z12*QCciU+u85 z#FqPm1)*g@wSpyvNv0Cpm1X@eVP6^i?rahH>Ux@A2GwJh3{{HPne`8j$R$q PIL.Image.Image: + """Overlay the logo on an image.""" + logo = PIL.Image.open("assets/extreme.png", "RGBA") + logo = logo.resize((1024, 1024)) + img = img.resize((1024, 1024)) + # Use alpha overlay to merge the two + final = PIL.Image.new("RGBA", img.size) + final = Image.alpha_composite(final, img) + final = Image.alpha_composite(final, logo) + return final + + +def overlay_purple(img: PIL.Image.Image) -> PIL.Image.Image: + """Overlay the purple on an image.""" + # purple_overlay_rgb = 0x440099 + purple_overlay_rgba = (68, 0, 153, 0.5) + # Create the overlay image + overlay = PIL.Image.new("RGBA", img.size, purple_overlay_rgba) + + # resize to 1024x1024 + img = img.resize((1024, 1024)) + overlay = overlay.resize((1024, 1024)) + + # Use alpha overlay to merge the two + final = PIL.Image.new("RGBA", img.size) + final = Image.alpha_composite(final, img) + final = Image.alpha_composite(final, overlay) + return final + + +def extremify(img: PIL.Image.Image) -> PIL.Image.Image: + """Apply the EXTREME effect to an image.""" + img = overlay_logo(img) + img = overlay_purple(img) + return img + + +class Extremism(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.slash_command(name="radicalise") + async def radicalise(self, ctx, image: discord.Attachment): + """Makes an image extremely radical.""" + if not image.content_type.startswith("image/"): + await ctx.send("That's not an image!") + return + await ctx.defer() + # Download the image + _img_bytes = await image.read() + # Open the image + img = PIL.Image.open(io.BytesIO(_img_bytes), "RGBA") + # Apply the EXTREME effect + img = await asyncio.to_thread(extremify, img) + # Save the image + img_bytes = io.BytesIO() + img.save(img_bytes, format="PNG") + img_bytes.seek(0) + # Send the image + await ctx.respond(file=discord.File(img_bytes, filename="extreme.png")) + + +def setup(bot): + bot.add_cog(Extremism(bot))