import PIL
import PIL.Image

from konabot.common.path import ASSETS_PATH
from konabot.common.utils.to_async import make_async

doubao_watermark = PIL.Image.open(ASSETS_PATH / "img" / "meme" / "doubao.png").convert("RGBA")


@make_async
def draw_doubao_watermark(base: PIL.Image.Image) -> PIL.Image.Image:
    base = base.copy().convert("RGBA")
    w = base.size[0] / 768 * 140
    h = base.size[0] / 768 * 40
    x = base.size[0] / 768 * 160
    y = base.size[0] / 768 * 60
    w, h, x, y = map(int, (w, h, x, y))
    base.alpha_composite(doubao_watermark.resize((w, h)), (base.size[0] - x, base.size[1] - y))
    return base

