mirror of
https://github.com/Ryujinx/ryuko-ng.git
synced 2024-12-22 20:15:30 +00:00
add .cox
Literal bloat
This commit is contained in:
parent
f44e1ea17b
commit
e4fcc81a13
|
@ -61,6 +61,7 @@ initial_extensions = ['cogs.common',
|
|||
'cogs.remind',
|
||||
'cogs.robocronp',
|
||||
'cogs.meme',
|
||||
'cogs.imagemanip',
|
||||
'cogs.pin',
|
||||
'cogs.invites']
|
||||
|
||||
|
|
1
assets/.gitignore
vendored
Normal file
1
assets/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
*.otf
|
BIN
assets/byjcox.png
Normal file
BIN
assets/byjcox.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.6 KiB |
BIN
assets/motherboardlogo.png
Normal file
BIN
assets/motherboardlogo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.6 KiB |
80
cogs/imagemanip.py
Normal file
80
cogs/imagemanip.py
Normal file
|
@ -0,0 +1,80 @@
|
|||
import discord
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands import Cog
|
||||
import textwrap
|
||||
import PIL.Image
|
||||
import PIL.ImageFilter
|
||||
import PIL.ImageOps
|
||||
import PIL.ImageFont
|
||||
import PIL.ImageDraw
|
||||
|
||||
|
||||
class ImageManip(Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.command()
|
||||
async def cox(self, ctx, *headline: str):
|
||||
"""Gives a cox headline"""
|
||||
mention = ctx.author.mention
|
||||
|
||||
in_vice = "assets/motherboardlogo.png"
|
||||
in_byjcox = "assets/byjcox.png"
|
||||
font_path = "assets/neue-haas-grotesk-display-bold-regular.otf"
|
||||
|
||||
# Settings for image generation, don't touch anything
|
||||
horipos = 18
|
||||
vertpos = 75
|
||||
line_spacing = 10
|
||||
font_size = 50
|
||||
image_width = 750
|
||||
font_wrap_count = 30
|
||||
sig_height = 15
|
||||
|
||||
# Wrap into lines
|
||||
lines = textwrap.wrap(headline, width=font_wrap_count)
|
||||
# not great, 4am be like
|
||||
image_height = (len(lines) + 2) * (vertpos + line_spacing)
|
||||
|
||||
# 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="#FFFFFF")
|
||||
moboim = PIL.Image.open(in_vice)
|
||||
im.paste(moboim, (horipos, 17))
|
||||
|
||||
# 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),
|
||||
(0, 0, 0)), (horipos, vertpos), w)
|
||||
|
||||
# Calculate position on next line
|
||||
vertpos += size[1] + line_spacing
|
||||
|
||||
# Add jcox signature
|
||||
jcoxim = PIL.Image.open(in_byjcox)
|
||||
im.paste(jcoxim, (horipos, vertpos + sig_height))
|
||||
|
||||
# Crop the image to the actual resulting size
|
||||
im = im.crop((0, 0, image_width, vertpos + (sig_height * 3)))
|
||||
|
||||
# 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))
|
|
@ -5,3 +5,6 @@ humanize
|
|||
parsedatetime
|
||||
aiohttp
|
||||
gidgethub
|
||||
|
||||
# Only if you'll enable imagemanip, which is only used for meme commands
|
||||
Pillow
|
||||
|
|
Loading…
Reference in a new issue