from PIL import Image, ImageDraw, ImageFont
from io import BytesIO

def make(io:BytesIO, top, bottom) -> BytesIO:
    img = Image.open(io).convert('RGBA')

    string = {
        "top": top.upper(),
        "bottom": bottom.upper()
    }
    size = {
        "x": img.size[0],
        "y": img.size[1]
    }

    draw = ImageDraw.Draw(img)
    size["toptext"], size["bottomtext"] = {}, {}

    font = ImageFont.truetype('impact.ttf', 100)
    size["toptext"]["x"], size["toptext"]["y"] = draw.textsize(string["top"], font=font)

    count = 0
    while size["toptext"]["x"] > size['x']-50 or size['toptext']['y'] > size['y']-50:
        count += 1
        font = ImageFont.truetype('impact.ttf', 100 - count)
        size["toptext"]["x"], size["toptext"]["y"] = draw.textsize(string["top"], font=font)

    draw.text(
        ((size["x"] - size["toptext"]["x"]) / 2, 10),
        string["top"],
        font=font,
        fill=(255, 255, 255),
        stroke_fill=(0, 0, 0),
        stroke_width=3
    )

    font = ImageFont.truetype('impact.ttf', 100)
    size["bottomtext"]["x"], size["bottomtext"]["y"] = draw.textsize(string["bottom"], font=font)

    count = 0
    while size["bottomtext"]["x"] > size['x']-50 or size['bottomtext']['y'] > size['y']-50:
        count += 1
        font = ImageFont.truetype('impact.ttf', 100 - count)
        size["bottomtext"]["x"], size["bottomtext"]["y"] = draw.textsize(string["bottom"], font=font)

    draw.text(
        ((size["x"] - size["bottomtext"]["x"]) / 2, size["y"] - 10 - size["bottomtext"]["y"]),
        string["bottom"],
        font=font,
        fill=(255, 255, 255),
        stroke_fill=(0, 0, 0),
        stroke_width=3
    )

    img = img.convert('RGB')
    newimg = BytesIO()
    img.save(newimg, 'PNG')
    newimg.seek(0)
    return newimg
