mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-29 00:32:06 +08:00
chore/cleanup-dependencies (#1763)
* ➖ 移除opencv-python, aiohttp依赖,更新poetry.source配置格式 * 💚 更新pre-commit配置文件 * 🚨 移除无用导入
This commit is contained in:
@@ -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值
|
||||
|
||||
|
||||
Reference in New Issue
Block a user