
使用方式
关于
专为 Slack 优化的动态 GIF 创作工具包,内置尺寸约束校验器和可组合的动画原语。当用户描述"帮我做一个 X 做 Y 的 Slack GIF"时触发。
Slack GIF 创建器 - 灵活工具包
用于创建针对 Slack 优化的动画 GIF 的工具包。提供 Slack 约束验证器、可组合的动画原语和可选的辅助工具。可以根据需要以任何方式应用这些工具来实现创意愿景。
Slack 的要求
Slack 根据用途对 GIF 有特定要求:
消息 GIF:
- 最大大小:约 2MB
- 最佳尺寸:480x480
- 典型帧率:15-20
- 颜色限制:128-256
- 时长:2-5 秒
表情 GIF:
- 最大大小:64KB(严格限制)
- 最佳尺寸:128x128
- 典型帧率:10-12
- 颜色限制:32-48
- 时长:1-2 秒
表情 GIF 具有挑战性 - 64KB 限制非常严格。有帮助的策略:
- 限制总帧数为 10-15 帧
- 最多使用 32-48 种颜色
- 保持设计简洁
- 避免渐变
- 频繁验证文件大小
工具包结构
本技能提供三类工具:
- 验证器 - 检查 GIF 是否满足 Slack 要求
- 动画原语 - 可组合的运动构建块(抖动、弹跳、移动、万花筒)
- 辅助工具 - 用于常见需求的可选函数(文本、颜色、效果)
在如何应用这些工具方面拥有完全的创作自由。
核心验证器
要确保 GIF 满足 Slack 的约束,使用这些验证器:
from core.gif_builder import GIFBuilder
# 创建 GIF 后,检查是否满足要求
builder = GIFBuilder(width=128, height=128, fps=10)
# ... 以任何方式添加帧 ...
# 保存并检查大小
info = builder.save('emoji.gif', num_colors=48, optimize_for_emoji=True)
# save 方法会在文件超出限制时自动警告
# info 字典包含:size_kb、size_mb、frame_count、duration_seconds
文件大小验证器:
from core.validators import check_slack_size
# 检查 GIF 是否满足大小限制
passes, info = check_slack_size('emoji.gif', is_emoji=True)
# 返回:(True/False, 包含大小详情的字典)
尺寸验证器:
from core.validators import validate_dimensions
# 检查尺寸
passes, info = validate_dimensions(128, 128, is_emoji=True)
# 返回:(True/False, 包含尺寸详情的字典)
完整验证:
from core.validators import validate_gif, is_slack_ready
# 运行所有验证
all_pass, results = validate_gif('emoji.gif', is_emoji=True)
# 或快速检查
if is_slack_ready('emoji.gif', is_emoji=True):
print("准备上传!")
动画原语
这些是可组合的运动构建块。可以将它们以任意组合应用于任何对象:
抖动
from templates.shake import create_shake_animation
# 抖动一个表情
frames = create_shake_animation(
object_type='emoji',
object_data={'emoji': '😱', 'size': 80},
num_frames=20,
shake_intensity=15,
direction='both' # 或 'horizontal'、'vertical'
)
弹跳
from templates.bounce import create_bounce_animation
# 弹跳一个圆形
frames = create_bounce_animation(
object_type='circle',
object_data={'radius': 40, 'color': (255, 100, 100)},
num_frames=30,
bounce_height=150
)
旋转
from templates.spin import create_spin_animation, create_loading_spinner
# 顺时针旋转
frames = create_spin_animation(
object_type='emoji',
object_data={'emoji': '🔄', 'size': 100},
rotation_type='clockwise',
full_rotations=2
)
# 摇摆旋转
frames = create_spin_animation(rotation_type='wobble', full_rotations=3)
# 加载旋转器
frames = create_loading_spinner(spinner_type='dots')
脉冲 / 心跳
from templates.pulse import create_pulse_animation, create_attention_pulse
# 平滑脉冲
frames = create_pulse_animation(
object_data={'emoji': '❤️', 'size': 100},
pulse_type='smooth',
scale_range=(0.8, 1.2)
)
# 心跳(双泵)
frames = create_pulse_animation(pulse_type='heartbeat')
# 表情 GIF 的注意力脉冲
frames = create_attention_pulse(emoji='⚠️', num_frames=20)
淡入淡出
from templates.fade import create_fade_animation, create_crossfade
# 淡入
frames = create_fade_animation(fade_type='in')
# 淡出
frames = create_fade_animation(fade_type='out')
# 两个表情之间的交叉淡入淡出
frames = create_crossfade(
object1_data={'emoji': '😊', 'size': 100},
object2_data={'emoji': '😂', 'size': 100}
)
缩放
from templates.zoom import create_zoom_animation, create_explosion_zoom
# 戏剧性放大
frames = create_zoom_animation(
zoom_type='in',
scale_range=(0.1, 2.0),
add_motion_blur=True
)
# 缩小
frames = create_zoom_animation(zoom_type='out')
# 爆炸缩放
frames = create_explosion_zoom(emoji='💥')
爆炸 / 碎裂
from templates.explode import create_explode_animation, create_particle_burst
# 爆裂爆炸
frames = create_explode_animation(
explode_type='burst',
num_pieces=25
)
# 碎裂效果
frames = create_explode_animation(explode_type='shatter')
兼容工具
Claude CodeCursor
标签
通用
