Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9b0a0368fa |
@ -2,6 +2,7 @@ from io import BytesIO
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
from loguru import logger
|
||||||
from nonebot.adapters import Event as BaseEvent
|
from nonebot.adapters import Event as BaseEvent
|
||||||
from nonebot.adapters import Bot as BaseBot
|
from nonebot.adapters import Bot as BaseBot
|
||||||
from nonebot.plugin import PluginMetadata
|
from nonebot.plugin import PluginMetadata
|
||||||
@ -117,16 +118,17 @@ async def handle_ytpgif(event: BaseEvent, bot: BaseBot, speed: float = 1.0):
|
|||||||
try:
|
try:
|
||||||
n_frames = getattr(src_img, "n_frames", 1)
|
n_frames = getattr(src_img, "n_frames", 1)
|
||||||
is_animated = n_frames > 1
|
is_animated = n_frames > 1
|
||||||
|
logger.debug(f"收到的动图的运动状态:{is_animated} 帧数量:{n_frames}")
|
||||||
except Exception:
|
except Exception:
|
||||||
is_animated = False
|
is_animated = False
|
||||||
n_frames = 1
|
n_frames = 1
|
||||||
|
|
||||||
output_frames = []
|
output_frames = []
|
||||||
output_durations_ms = []
|
output_durations_ms = []
|
||||||
|
|
||||||
if is_animated:
|
if is_animated:
|
||||||
# === 动图模式:截取正向 + 镜像两段 ===
|
# === 动图模式:截取正向 + 镜像两段 ===
|
||||||
frames_with_duration = []
|
frames_with_duration: list[tuple[Image.Image, float]] = []
|
||||||
palette = src_img.getpalette()
|
palette = src_img.getpalette()
|
||||||
|
|
||||||
for idx in range(n_frames):
|
for idx in range(n_frames):
|
||||||
@ -148,6 +150,7 @@ async def handle_ytpgif(event: BaseEvent, bot: BaseBot, speed: float = 1.0):
|
|||||||
try:
|
try:
|
||||||
resized_frame.putpalette(palette)
|
resized_frame.putpalette(palette)
|
||||||
except Exception: # noqa
|
except Exception: # noqa
|
||||||
|
logger.debug("色板应用失败")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
ms = frame.info.get("duration", int(BASE_SEGMENT_DURATION * 1000))
|
ms = frame.info.get("duration", int(BASE_SEGMENT_DURATION * 1000))
|
||||||
|
|||||||
Reference in New Issue
Block a user