diff --git a/assets/trumpfooter.png b/assets/trumpfooter.png new file mode 100644 index 0000000..4e81e34 Binary files /dev/null and b/assets/trumpfooter.png differ diff --git a/assets/trumpheader.png b/assets/trumpheader.png new file mode 100644 index 0000000..34efe9e Binary files /dev/null and b/assets/trumpheader.png differ diff --git a/cogs/imagemanip.py b/cogs/imagemanip.py index abf4412..031e82c 100644 --- a/cogs/imagemanip.py +++ b/cogs/imagemanip.py @@ -77,6 +77,69 @@ class ImageManip(Cog): await ctx.send(content=f"{mention}: Enjoy.", file=discord.File(out_filename)) + @commands.check(check_if_staff_or_ot) + @commands.command(hidden=True) + async def trump(self, ctx, *, headline: str): + """Gives a trump tweet""" + mention = ctx.author.mention + + in_header = "assets/trumpheader.png" + in_footer = "assets/trumpfooter.png" + font_path = "assets/Segoe UI.ttf" + + # Settings for image generation, don't touch anything + horipos = 10 + vertpos = 70 + font_size = 27 + image_width = 590 + font_wrap_count = 45 + sig_height = 49 + + # Wrap into lines + lines = textwrap.wrap(headline, width=font_wrap_count) + # not great, 4am be like + image_height = (len(lines) + 2) * vertpos + + # Load font + f = PIL.ImageFont.truetype(font_path, font_size) + + # Create image base, paste mobo logo + im = PIL.Image.new("RGB", (image_width, image_height), color="#15202B") + headerim = PIL.Image.open(in_header) + im.paste(headerim, (horipos, 15)) + + # Go through all the wrapped text lines + for line in lines: + # Get size of the text by font, create a new image of that size + size = f.getsize(line) + txt = PIL.Image.new('L', size) + + # Draw the text + d = PIL.ImageDraw.Draw(txt) + d.text((0, 0), line, font=f, fill=255) + + # Paste the text into the base image + w = txt.rotate(0, expand=1) + im.paste(PIL.ImageOps.colorize(w, (0, 0, 0), + (255, 255, 255)), (horipos, vertpos), + w) + + # Calculate position on next line + vertpos += size[1] + + # Add jcox signature + jcoxim = PIL.Image.open(in_footer) + im.paste(jcoxim, (horipos, vertpos + int(sig_height / 3))) + + # Crop the image to the actual resulting size + im = im.crop((0, 0, image_width, vertpos + int(sig_height * 2.5))) + + # Save image + out_filename = f"/tmp/{ctx.message.id}-out.png" + im.save(out_filename, quality=100, optimize=True) + await ctx.send(content=f"{mention}: Enjoy.", + file=discord.File(out_filename)) + def setup(bot): bot.add_cog(ImageManip(bot))