Sarenrae: fix image manipulation
This commit is contained in:
parent
b9929e1c1c
commit
f0e125b736
@ -3,16 +3,19 @@ import discord
|
||||
import requests
|
||||
import imgkit
|
||||
from PIL import Image, ImageOps
|
||||
import os
|
||||
import io
|
||||
|
||||
UID = 0x181eff7aacab91fa4051d1d995d44050
|
||||
|
||||
|
||||
def image(name, html):
|
||||
def image(html):
|
||||
open_image = imgkit.from_string(html, False)
|
||||
open_image = Image.open(open_image)
|
||||
open_image = Image.open(io.BytesIO(open_image))
|
||||
image_box = ImageOps.invert(open_image.convert("RGB")).getbbox()
|
||||
open_image.crop(image_box).save(f"{name}_cropped.png")
|
||||
file = io.BytesIO()
|
||||
open_image.crop(image_box).save(file, "JPEG")
|
||||
file.seek(0)
|
||||
return file
|
||||
|
||||
|
||||
class Sarenrae(commands.Cog):
|
||||
@ -30,11 +33,7 @@ class Sarenrae(commands.Cog):
|
||||
headers = {"Authorization": await self.conf.token()}
|
||||
req = requests.get(f"https://api.pathfinder2.fr/v1/pf2/ancestry?name={name}", headers=headers).json()
|
||||
html = req["results"][0]["data"]["description"]["value"]
|
||||
filename = f"ancestry-{name}"
|
||||
image(filename, html)
|
||||
await ctx.send(file=discord.File(open(f"ancestry/{name}.png", "rb")))
|
||||
os.remove(f"{filename}.png")
|
||||
os.remove(f"{filename}_cropped.png")
|
||||
await ctx.send(file=discord.File(image(html)))
|
||||
|
||||
@commands.command()
|
||||
@checks.is_owner()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user