mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-29 00:32:06 +08:00
feat✨: 色图
This commit is contained in:
@@ -4,8 +4,11 @@ import re
|
||||
from pathlib import Path
|
||||
from typing import Awaitable, Callable
|
||||
|
||||
import cv2
|
||||
from nonebot.utils import is_coroutine_callable
|
||||
|
||||
from zhenxun.configs.path_config import IMAGE_PATH
|
||||
|
||||
from ._build_image import BuildImage, ColorAlias
|
||||
from ._build_mat import BuildMat, MatType
|
||||
from ._image_template import ImageTemplate, RowStyle
|
||||
@@ -337,3 +340,27 @@ async def build_sort_image(
|
||||
curr_h += img.height + 10
|
||||
curr_w += max([x.width for x in ig]) + 30
|
||||
return A
|
||||
|
||||
|
||||
def compressed_image(
|
||||
in_file: str | Path,
|
||||
out_file: str | Path | None = None,
|
||||
ratio: float = 0.9,
|
||||
):
|
||||
"""压缩图片
|
||||
|
||||
参数:
|
||||
in_file: 被压缩的文件路径
|
||||
out_file: 压缩后输出的文件路径
|
||||
ratio: 压缩率,宽高 * 压缩率
|
||||
"""
|
||||
in_file = IMAGE_PATH / in_file if isinstance(in_file, str) else in_file
|
||||
if out_file:
|
||||
out_file = IMAGE_PATH / out_file if isinstance(out_file, str) else out_file
|
||||
else:
|
||||
out_file = in_file
|
||||
h, w, d = cv2.imread(str(in_file.absolute())).shape
|
||||
img = cv2.resize(
|
||||
cv2.imread(str(in_file.absolute())), (int(w * ratio), int(h * ratio))
|
||||
)
|
||||
cv2.imwrite(str(out_file.absolute()), img)
|
||||
|
||||
@@ -7,6 +7,7 @@ from nonebot.adapters.kaiheila import Bot as KaiheilaBot
|
||||
from nonebot.adapters.onebot.v11 import Bot as v11Bot
|
||||
from nonebot.adapters.onebot.v12 import Bot as v12Bot
|
||||
from nonebot_plugin_session import EventSession
|
||||
from ruamel.yaml.comments import CommentedSeq
|
||||
|
||||
from zhenxun.services.log import logger
|
||||
|
||||
@@ -80,7 +81,7 @@ class WithdrawManager:
|
||||
if time:
|
||||
gid = None
|
||||
_time = 1
|
||||
if isinstance(time, tuple):
|
||||
if isinstance(time, (tuple, CommentedSeq)):
|
||||
if time[0] == 0:
|
||||
return
|
||||
if session:
|
||||
|
||||
Reference in New Issue
Block a user