mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-29 00:32:06 +08:00
@@ -12,6 +12,7 @@ from utils.message_builder import image
|
|||||||
from utils.utils import FreqLimiter, cn2py, get_message_text, is_number
|
from utils.utils import FreqLimiter, cn2py, get_message_text, is_number
|
||||||
|
|
||||||
from .rule import rule
|
from .rule import rule
|
||||||
|
from .anti import pix_random_change_file
|
||||||
|
|
||||||
__zx_plugin_name__ = "本地图库"
|
__zx_plugin_name__ = "本地图库"
|
||||||
__plugin_usage__ = f"""
|
__plugin_usage__ = f"""
|
||||||
@@ -74,6 +75,8 @@ async def _(event: MessageEvent):
|
|||||||
return
|
return
|
||||||
if int(index) > length - 1 or int(index) < 0:
|
if int(index) > length - 1 or int(index) < 0:
|
||||||
await send_img.finish(f"超过当前上下限!({length - 1})")
|
await send_img.finish(f"超过当前上下限!({length - 1})")
|
||||||
|
abs_path = os.path.join(os.getcwd(), path / f"{index}.jpg")
|
||||||
|
pix_random_change_file(abs_path)
|
||||||
result = image(path / f"{index}.jpg")
|
result = image(path / f"{index}.jpg")
|
||||||
if result:
|
if result:
|
||||||
logger.info(
|
logger.info(
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import cv2
|
||||||
|
import random
|
||||||
|
import warnings
|
||||||
|
import numpy as np
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
|
def pix_random_change(img):
|
||||||
|
# Image转cv2
|
||||||
|
img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
|
||||||
|
img[0, 0, 0] = random.randint(0, 0xfffffff)
|
||||||
|
# cv2转Image
|
||||||
|
img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
|
||||||
|
return img
|
||||||
|
|
||||||
|
|
||||||
|
def pix_random_change_file(path: str):
|
||||||
|
# 注意:cv2.imread()不支持路径中文
|
||||||
|
warnings.filterwarnings("ignore", category=Warning)
|
||||||
|
img = cv2.imread(path)
|
||||||
|
img[0, 0, 0] = random.randint(0, 0xfffffff)
|
||||||
|
cv2.imwrite(path, img)
|
||||||
|
|
||||||
Reference in New Issue
Block a user