Compare commits

...

3 Commits

Author SHA1 Message Date
e72bc283f8 调整 giftool
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2025-10-12 15:18:07 +08:00
c9d58e7498 修改文档
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2025-10-12 13:45:34 +08:00
627a48da1c 添加安全限制 2025-10-12 13:40:40 +08:00
3 changed files with 49 additions and 9 deletions

View File

@ -5,11 +5,19 @@
shadertool [选项] <SkSL 代码>
示例
`shadertool "void main() { sk_FragColor = vec4(sin(sk_FragCoord.x * 0.01), 0, 0, 1); }"`
使用默认参数320×1801秒15fps渲染一段红色水平波纹动画。
shadertool """
uniform float u_time;
uniform float2 u_resolution;
`shadertool --width 256 --height 256 --duration 2.0 --fps 20 "void main() { sk_FragColor = vec4(fract(sk_FragCoord * 0.02), 1); }"`
以 256×256 分辨率、2 秒时长、20 帧每秒渲染一个彩色格点动画。
half4 main(float2 coord) {
return half4(
1.0,
sin((coord.y / u_resolution.y + u_time) * 3.1415926 * 2) * 0.5 + 0.5,
coord.x / u_resolution.x,
1.0
);
}
"""
参数说明
SkSL 代码(必填)

View File

@ -141,17 +141,47 @@ async def _(
output_img = BytesIO()
adjusted_durations = [
max(10, int(dur / speed_factor)) for dur in selected_durations
dur / speed_factor for dur in selected_durations
]
if selected_frames:
selected_frames[0].save(
rframes = []
rdur = []
acc_mod_20 = 0
for i in range(len(selected_frames)):
fr = selected_frames[i]
du: float = adjusted_durations[i]
if du >= 20:
rframes.append(fr)
rdur.append(int(du))
acc_mod_20 = 0
else:
if acc_mod_20 == 0:
rframes.append(fr)
rdur.append(20)
acc_mod_20 += du
else:
acc_mod_20 += du
if acc_mod_20 >= 20:
acc_mod_20 = 0
if len(rframes) == 1 and len(selected_frames) > 1:
rframes.append(selected_frames[max(2, len(selected_frames) // 2)])
rdur.append(20)
if rframes:
rframes[0].save(
output_img,
format="GIF",
save_all=True,
append_images=selected_frames[1:],
duration=adjusted_durations,
append_images=rframes[1:],
duration=rdur,
loop=0,
optimize=False,
disposal=2,
transparency=0,
)
else:
raise BotExceptionMessage("错误:没有可输出的帧")

View File

@ -31,6 +31,8 @@ async def _(
raise BotExceptionMessage("时长太短或帧率太小,没有帧被渲染")
if fps_ * duration_ > 100:
raise BotExceptionMessage("太多帧啦!试着缩短一点时间吧!")
if width_ > 640 or height_ > 640:
raise BotExceptionMessage("最大支持 640x640 啦!不要太大啦!")
code = code.strip("\"").strip("'")