From 6c80bb6629fe2acfda93e8f614721cf862655c0d Mon Sep 17 00:00:00 2001 From: BalconyJH Date: Thu, 12 Dec 2024 05:35:04 +0800 Subject: [PATCH] =?UTF-8?q?:rotating=5Flight:=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E6=97=A0=E7=94=A8=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.py | 2 +- zhenxun/utils/image_utils.py | 27 +-------------------------- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/bot.py b/bot.py index 6f1ec9c5..76fe8204 100644 --- a/bot.py +++ b/bot.py @@ -14,7 +14,7 @@ driver.register_adapter(KaiheilaAdapter) driver.register_adapter(DoDoAdapter) # driver.register_adapter(DiscordAdapter) -from zhenxun.services.db_context import init, disconnect +from zhenxun.services.db_context import disconnect, init driver.on_startup(init) driver.on_shutdown(disconnect) diff --git a/zhenxun/utils/image_utils.py b/zhenxun/utils/image_utils.py index 1659ff5c..d5affc7d 100644 --- a/zhenxun/utils/image_utils.py +++ b/zhenxun/utils/image_utils.py @@ -5,12 +5,11 @@ from pathlib import Path import random import re -import cv2 import imagehash from nonebot.utils import is_coroutine_callable from PIL import Image -from zhenxun.configs.path_config import IMAGE_PATH, TEMP_PATH +from zhenxun.configs.path_config import TEMP_PATH from zhenxun.services.log import logger from zhenxun.utils.http_utils import AsyncHttpx @@ -347,30 +346,6 @@ async def build_sort_image( 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) - - def get_img_hash(image_file: str | Path) -> str: """获取图片的hash值