From 9b0a0368fa3c8ded211411678ada7e5dd11cefb2 Mon Sep 17 00:00:00 2001 From: passthem Date: Sun, 12 Oct 2025 10:55:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20YTPGIF=20=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- konabot/plugins/ytpgif/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/konabot/plugins/ytpgif/__init__.py b/konabot/plugins/ytpgif/__init__.py index 2be0a62..42c9354 100644 --- a/konabot/plugins/ytpgif/__init__.py +++ b/konabot/plugins/ytpgif/__init__.py @@ -2,6 +2,7 @@ from io import BytesIO from typing import Optional from PIL import Image +from loguru import logger from nonebot.adapters import Event as BaseEvent from nonebot.adapters import Bot as BaseBot from nonebot.plugin import PluginMetadata @@ -117,16 +118,17 @@ async def handle_ytpgif(event: BaseEvent, bot: BaseBot, speed: float = 1.0): try: n_frames = getattr(src_img, "n_frames", 1) is_animated = n_frames > 1 + logger.debug(f"收到的动图的运动状态:{is_animated} 帧数量:{n_frames}") except Exception: is_animated = False - n_frames = 1 + n_frames = 1 output_frames = [] output_durations_ms = [] if is_animated: # === 动图模式:截取正向 + 镜像两段 === - frames_with_duration = [] + frames_with_duration: list[tuple[Image.Image, float]] = [] palette = src_img.getpalette() for idx in range(n_frames): @@ -148,6 +150,7 @@ async def handle_ytpgif(event: BaseEvent, bot: BaseBot, speed: float = 1.0): try: resized_frame.putpalette(palette) except Exception: # noqa + logger.debug("色板应用失败") pass ms = frame.info.get("duration", int(BASE_SEGMENT_DURATION * 1000))