Merge pull request '添加豆包水印' (#46) from feature/doubao-watermark into master
Reviewed-on: #46
This commit is contained in:
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_pt,
|
||||||
draw_suan,
|
draw_suan,
|
||||||
)
|
)
|
||||||
|
from konabot.plugins.memepack.drawing.watermark import draw_doubao_watermark
|
||||||
|
|
||||||
from nonebot.adapters import Bot, Event
|
from nonebot.adapters import Bot, Event
|
||||||
|
|
||||||
@ -342,3 +343,16 @@ async def _(quote: str, author: str, img: PIL_Image):
|
|||||||
)
|
)
|
||||||
await quote_cmd.send(await UniMessage().image(raw=out).export())
|
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())
|
||||||
|
|||||||
15
konabot/plugins/memepack/drawing/watermark.py
Normal file
15
konabot/plugins/memepack/drawing/watermark.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
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").resize((140, 40))
|
||||||
|
|
||||||
|
|
||||||
|
@make_async
|
||||||
|
def draw_doubao_watermark(base: PIL.Image.Image) -> PIL.Image.Image:
|
||||||
|
base = base.copy().convert("RGBA")
|
||||||
|
base.alpha_composite(doubao_watermark, (base.size[0] - 160, base.size[1] - 60))
|
||||||
|
return base
|
||||||
|
|
||||||
Reference in New Issue
Block a user