Skip to content

Commit

Permalink
fixed: 修复了猜卡 字符画排列错误问题
Browse files Browse the repository at this point in the history
  • Loading branch information
fireinsect committed Jun 28, 2024
1 parent ac3549c commit 46f8522
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
17 changes: 9 additions & 8 deletions nonebot_plugin_ocgbot_v2/libraries/charpic.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Binary file not shown.
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
readme = "README.md"
Expand All @@ -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 = [
Expand Down

0 comments on commit 46f8522

Please sign in to comment.