Sarenrae: Fix error with image creation
This commit is contained in:
parent
54cdc26137
commit
735f1b057d
@ -3,6 +3,7 @@ import discord
|
|||||||
import requests
|
import requests
|
||||||
import htmlwebshot
|
import htmlwebshot
|
||||||
from PIL import Image, ImageOps
|
from PIL import Image, ImageOps
|
||||||
|
import os
|
||||||
|
|
||||||
photographer = htmlwebshot.WebShot()
|
photographer = htmlwebshot.WebShot()
|
||||||
|
|
||||||
@ -10,7 +11,7 @@ photographer = htmlwebshot.WebShot()
|
|||||||
def image(name, html):
|
def image(name, html):
|
||||||
photographer.create_pic(html=html, output=f"{name}.png")
|
photographer.create_pic(html=html, output=f"{name}.png")
|
||||||
open_image = Image.open(f"{name}.png")
|
open_image = Image.open(f"{name}.png")
|
||||||
image_box = ImageOps.invert(open_image.convert("RGB")).getbox()
|
image_box = ImageOps.invert(open_image.convert("RGB")).getbbox()
|
||||||
open_image.crop(image_box).save(f"{name}_cropped.png")
|
open_image.crop(image_box).save(f"{name}_cropped.png")
|
||||||
|
|
||||||
|
|
||||||
@ -25,11 +26,14 @@ class Sarenrae(commands.Cog):
|
|||||||
headers = {"Authorization": self.token}
|
headers = {"Authorization": self.token}
|
||||||
req = requests.get(f"https://api.pathfinder2.fr/v1/pf2/ancestry?name={name}", headers=headers).json()
|
req = requests.get(f"https://api.pathfinder2.fr/v1/pf2/ancestry?name={name}", headers=headers).json()
|
||||||
html = req["results"][0]["data"]["description"]["value"]
|
html = req["results"][0]["data"]["description"]["value"]
|
||||||
image(f"ancestry/{name}", html)
|
filename = f"ancestry-{name}"
|
||||||
|
image(filename, html)
|
||||||
await ctx.send(file=discord.File(open(f"ancestry/{name}.png", "rb")))
|
await ctx.send(file=discord.File(open(f"ancestry/{name}.png", "rb")))
|
||||||
|
os.remove(f"{filename}.png")
|
||||||
|
os.remove(f"{filename}_cropped.png")
|
||||||
|
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def sarenrae_token(self, ctx, *args):
|
async def sarenrae_token(self, ctx, *args):
|
||||||
self.token = args[0]
|
self.token = args[0]
|
||||||
return await ctx.send(f"Set token to {self.token}")
|
return await ctx.send(f"Set token to {self.token}")
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user