Compare commits
6 Commits
v0.9.17
...
feature/do
| Author | SHA1 | Date | |
|---|---|---|---|
| 751297e3bc | |||
| b450998f3f | |||
| ae6297b98d | |||
| dacae29054 | |||
| 8acb546c6a | |||
| 49e0914416 |
BIN
assets/img/meme/doubao.png
Executable file
BIN
assets/img/meme/doubao.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 8.0 KiB |
@ -34,6 +34,7 @@ from konabot.plugins.memepack.drawing.saying import (
|
||||
draw_pt,
|
||||
draw_suan,
|
||||
)
|
||||
from konabot.plugins.memepack.drawing.watermark import draw_doubao_watermark
|
||||
|
||||
from nonebot.adapters import Bot, Event
|
||||
|
||||
@ -331,7 +332,9 @@ async def _(quote: str, author: str, img: PIL_Image):
|
||||
await page.locator('input[name=quote]').fill(quote)
|
||||
await page.locator('input[name=author]').fill(author)
|
||||
|
||||
await page.wait_for_timeout(500)
|
||||
await page.wait_for_load_state('networkidle')
|
||||
await page.wait_for_timeout(500)
|
||||
|
||||
out = await WebRenderer.render(
|
||||
konaweb('makequote'),
|
||||
@ -340,3 +343,16 @@ async def _(quote: str, author: str, img: PIL_Image):
|
||||
)
|
||||
await quote_cmd.send(await UniMessage().image(raw=out).export())
|
||||
|
||||
|
||||
doubao_cmd = on_alconna(Alconna(
|
||||
"豆包水印",
|
||||
Args["image?", Image | None],
|
||||
))
|
||||
|
||||
|
||||
@doubao_cmd.handle()
|
||||
async def _(img: PIL_Image):
|
||||
result = await draw_doubao_watermark(img)
|
||||
result_bytes = BytesIO()
|
||||
result.save(result_bytes, format="PNG")
|
||||
await doubao_cmd.send(await UniMessage().image(raw=result_bytes).export())
|
||||
|
||||
20
konabot/plugins/memepack/drawing/watermark.py
Normal file
20
konabot/plugins/memepack/drawing/watermark.py
Normal file
@ -0,0 +1,20 @@
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user