feat: add --pingpong flag to giftool

Add pingpong mode to giftool command. When --pingpong flag is used,
the generated GIF will play forward then backward, creating a
back-and-forth looping effect.

Features:
- Add --pingpong option to giftool command
- Support combining with --speed for adjusted playback speed
- Update documentation with new option

Examples:
- giftool [图片] --pingpong
- giftool [图片] --pingpong --speed 2.0
This commit is contained in:
2026-04-02 20:06:15 +08:00
parent 51c0bf4229
commit b87c58485c
2 changed files with 20 additions and 0 deletions

View File

@ -34,6 +34,7 @@ cmd_giftool = on_alconna(
Option("-t", Args["length", str]),
Option("-to", Args["end_point", str]),
Option("--speed", Args["speed_factor", float], default=1.0, alias=["-s"]),
Option("--pingpong", default=False),
)
)
@ -46,6 +47,7 @@ async def _(
length: str | None = None,
speed_factor: float = 1.0,
end_point: str | None = None,
pingpong: bool = False,
):
ss: None | float = None
if start_point:
@ -162,6 +164,16 @@ async def _(
rframes = rframes[::-1]
rdur_ms = rdur_ms[::-1]
# 处理 pingpong 模式
if pingpong:
# 复制一份反转的帧序列(去掉第一帧避免重复)
pingpong_frames = rframes[1:][::-1] if len(rframes) > 1 else rframes[::-1]
pingpong_durations = rdur_ms[1:][::-1] if len(rdur_ms) > 1 else rdur_ms[::-1]
# 拼接正放和倒放
rframes = rframes + pingpong_frames
rdur_ms = rdur_ms + pingpong_durations
output_img = BytesIO()
if rframes: