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

@ -71,6 +71,14 @@ giftool [图片] [选项]
- 调整 GIF 图的速度。若为负数,则代表倒放。
### `--pingpong`(可选)
- 开启乒乓模式,生成正放-倒放拼接的 GIF 图。
- 即播放完正向后,会倒放回去,形成往复循环效果。
- 可与 `--speed` 配合使用,调整播放速度。
- 示例:`giftool [图片] --pingpong`
- 示例:`giftool [图片] --pingpong --speed 2.0`
## 使用方式
1. 发送指令前,请确保:

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: