diff --git a/nonebot_plugin_ocgbot_v2/libraries/charpic.py b/nonebot_plugin_ocgbot_v2/libraries/charpic.py index 503a79f..b6fb79b 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/charpic.py +++ b/nonebot_plugin_ocgbot_v2/libraries/charpic.py @@ -1,20 +1,21 @@ -from PIL import Image, ImageDraw -from pil_utils import BuildImage -from pil_utils.fonts import Font +from pathlib import Path +from PIL import Image, ImageDraw, ImageFont +from nonebot_plugin_ocgbot_v2.libraries.globalMessage import font_path + +fontpath = str(Path(font_path) / "consola.ttf") def charPic(img: Image) -> Image: str_map = "@@$$&B88QMMGW##EE93SPPDOOU**==()+^,\"--''. " num = len(str_map) - font = Font.find("Consolas").load_font(15) - img = BuildImage(img) - img = img.convert("L").resize_width(150) + font = ImageFont.truetype(fontpath, 15) + img = img.convert("L").resize((200, int(img.height * 200 / img.width))) img = img.resize((img.width, img.height // 2)) lines = [] for y in range(img.height): line = "" for x in range(img.width): - gray = img.image.getpixel((x, y)) + gray = img.getpixel((x, y)) line += str_map[int(num * gray / 256)] if gray != 0 else " " lines.append(line) text = "\n".join(lines) @@ -23,4 +24,4 @@ def charPic(img: Image) -> Image: _, _, w, h = draw.multiline_textbbox((0, 0), text, font=font) draw.multiline_text((0, 0), text, font=font, fill="black") text_img = text_img.crop((0, 0, w, h)) - return BuildImage(text_img).image + return text_img diff --git a/nonebot_plugin_ocgbot_v2/static/fonts/consola.ttf b/nonebot_plugin_ocgbot_v2/static/fonts/consola.ttf new file mode 100644 index 0000000..e881ca4 Binary files /dev/null and b/nonebot_plugin_ocgbot_v2/static/fonts/consola.ttf differ diff --git a/pyproject.toml b/pyproject.toml index d60d9d2..d259d61 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nonebot-plugin-ocgbot-v2" -version = "0.2.10.1" +version = "0.2.10.2" description = "nonebot-plugin-ocgbot-v2" authors = ["fireinsect <847954981@qq.com>"] readme = "README.md" @@ -16,8 +16,6 @@ Pillow = ">=9.5.0" httpx = ">=0.20.0,<1.0.0" numpy = ">=1.23.0" matplotlib = ">=3.7.1" -pil_utils = ">=0.1.7" -nonebot-plugin-localstore = "^0.4.0" [tool.nonebot] adapters = [