Slack GIF Creator
A toolkit providing utilities and knowledge for creating animated GIFs optimized for Slack.
Slack Requirements
Dimensions:
- - Emoji GIFs: 128x128 (recommended)
- Message GIFs: 480x480
Parameters:
- - FPS: 10-30 (lower is smaller file size)
- Colors: 48-128 (fewer = smaller file size)
- Duration: Keep under 3 seconds for emoji GIFs
Core Workflow
CODEBLOCK0
Drawing Graphics
Working with User-Uploaded Images
If a user uploads an image, consider whether they want to:
- - Use it directly (e.g., "animate this", "split this into frames")
- Use it as inspiration (e.g., "make something like this")
Load and work with images using PIL:
CODEBLOCK1
Drawing from Scratch
When drawing graphics from scratch, use PIL ImageDraw primitives:
CODEBLOCK2
Don't use: Emoji fonts (unreliable across platforms) or assume pre-packaged graphics exist in this skill.
Making Graphics Look Good
Graphics should look polished and creative, not basic. Here's how:
Use thicker lines - Always set width=2 or higher for outlines and lines. Thin lines (width=1) look choppy and amateurish.
Add visual depth:
- - Use gradients for backgrounds (
create_gradient_background) - Layer multiple shapes for complexity (e.g., a star with a smaller star inside)
Make shapes more interesting:
- - Don't just draw a plain circle - add highlights, rings, or patterns
- Stars can have glows (draw larger, semi-transparent versions behind)
- Combine multiple shapes (stars + sparkles, circles + rings)
Pay attention to colors:
- - Use vibrant, complementary colors
- Add contrast (dark outlines on light shapes, light outlines on dark shapes)
- Consider the overall composition
For complex shapes (hearts, snowflakes, etc.):
- - Use combinations of polygons and ellipses
- Calculate points carefully for symmetry
- Add details (a heart can have a highlight curve, snowflakes have intricate branches)
Be creative and detailed! A good Slack GIF should look polished, not like placeholder graphics.
Available Utilities
GIFBuilder (core.gif_builder)
Assembles frames and optimizes for Slack:
CODEBLOCK3
Validators (core.validators)
Check if GIF meets Slack requirements:
CODEBLOCK4
Easing Functions (core.easing)
Smooth motion instead of linear:
CODEBLOCK5
Frame Helpers (core.frame_composer)
Convenience functions for common needs:
CODEBLOCK6
Animation Concepts
Shake/Vibrate
Offset object position with oscillation:
- - Use
math.sin() or math.cos() with frame index - Add small random variations for natural feel
- Apply to x and/or y position
Pulse/Heartbeat
Scale object size rhythmically:
- - Use
math.sin(t * frequency * 2 * math.pi) for smooth pulse - For heartbeat: two quick pulses then pause (adjust sine wave)
- Scale between 0.8 and 1.2 of base size
Bounce
Object falls and bounces:
- - Use
interpolate() with easing='bounce_out' for landing - Use
easing='ease_in' for falling (accelerating) - Apply gravity by increasing y velocity each frame
Spin/Rotate
Rotate object around center:
- - PIL: INLINECODE12
- For wobble: use sine wave for angle instead of linear
Fade In/Out
Gradually appear or disappear:
- - Create RGBA image, adjust alpha channel
- Or use INLINECODE13
- Fade in: alpha from 0 to 1
- Fade out: alpha from 1 to 0
Slide
Move object from off-screen to position:
- - Start position: outside frame bounds
- End position: target location
- Use
interpolate() with easing='ease_out' for smooth stop - For overshoot: use INLINECODE16
Zoom
Scale and position for zoom effect:
- - Zoom in: scale from 0.1 to 2.0, crop center
- Zoom out: scale from 2.0 to 1.0
- Can add motion blur for drama (PIL filter)
Explode/Particle Burst
Create particles radiating outward:
- - Generate particles with random angles and velocities
- Update each particle:
x += vx, INLINECODE18 - Add gravity: INLINECODE19
- Fade out particles over time (reduce alpha)
Optimization Strategies
Only when asked to make the file size smaller, implement a few of the following methods:
- 1. Fewer frames - Lower FPS (10 instead of 20) or shorter duration
- Fewer colors -
num_colors=48 instead of 128 - Smaller dimensions - 128x128 instead of 480x480
- Remove duplicates -
remove_duplicates=True in save() - Emoji mode -
optimize_for_emoji=True auto-optimizes
CODEBLOCK7
Philosophy
This skill provides:
- - Knowledge: Slack's requirements and animation concepts
- Utilities: GIFBuilder, validators, easing functions
- Flexibility: Create the animation logic using PIL primitives
It does NOT provide:
- - Rigid animation templates or pre-made functions
- Emoji font rendering (unreliable across platforms)
- A library of pre-packaged graphics built into the skill
Note on user uploads: This skill doesn't include pre-built graphics, but if a user uploads an image, use PIL to load and work with it - interpret based on their request whether they want it used directly or just as inspiration.
Be creative! Combine concepts (bouncing + rotating, pulsing + sliding, etc.) and use PIL's full capabilities.
Dependencies
CODEBLOCK8
Slack GIF 创建工具
提供用于创建针对 Slack 优化的动画 GIF 的工具包和相关知识。
Slack 要求
尺寸:
- - 表情符号 GIF:128x128(推荐)
- 消息 GIF:480x480
参数:
- - 帧率:10-30(越低文件越小)
- 颜色数:48-128(越少文件越小)
- 时长:表情符号 GIF 控制在 3 秒以内
核心工作流程
python
from core.gif_builder import GIFBuilder
from PIL import Image, ImageDraw
1. 创建构建器
builder = GIFBuilder(width=128, height=128, fps=10)
2. 生成帧
for i in range(12):
frame = Image.new(RGB, (128, 128), (240, 248, 255))
draw = ImageDraw.Draw(frame)
# 使用 PIL 基本绘图元素绘制动画
# (圆形、多边形、线条等)
builder.add_frame(frame)
3. 保存并优化
builder.save(output.gif, num
colors=48, optimizefor_emoji=True)
绘制图形
处理用户上传的图片
如果用户上传了图片,需考虑他们想要:
- - 直接使用(例如让这个动起来、将其拆分为帧)
- 作为灵感参考(例如制作类似的东西)
使用 PIL 加载和处理图片:
python
from PIL import Image
uploaded = Image.open(file.png)
直接使用,或仅作为颜色/风格的参考
从零开始绘制
从零开始绘制图形时,使用 PIL ImageDraw 基本绘图元素:
python
from PIL import ImageDraw
draw = ImageDraw.Draw(frame)
圆形/椭圆形
draw.ellipse([x1, y1, x2, y2], fill=(r, g, b), outline=(r, g, b), width=3)
星形、三角形、任意多边形
points = [(x1, y1), (x2, y2), (x3, y3), ...]
draw.polygon(points, fill=(r, g, b), outline=(r, g, b), width=3)
线条
draw.line([(x1, y1), (x2, y2)], fill=(r, g, b), width=5)
矩形
draw.rectangle([x1, y1, x2, y2], fill=(r, g, b), outline=(r, g, b), width=3)
不要使用: 表情符号字体(跨平台不可靠)或假定本技能中存在预置图形。
让图形更美观
图形应看起来精致且富有创意,而非简陋。以下是具体方法:
使用更粗的线条 - 轮廓和线条始终设置 width=2 或更高。细线条(width=1)看起来粗糙且业余。
增加视觉深度:
- - 使用渐变背景(creategradientbackground)
- 叠加多个形状增加复杂度(例如,大星星内含小星星)
让形状更有趣:
- - 不要只画普通圆形 - 添加高光、环或图案
- 星星可以添加光晕(在后面绘制更大、半透明的版本)
- 组合多个形状(星星+闪光、圆形+圆环)
注意色彩搭配:
- - 使用鲜艳的互补色
- 增加对比度(浅色形状用深色轮廓,深色形状用浅色轮廓)
- 考虑整体构图
对于复杂形状(心形、雪花等):
- - 使用多边形和椭圆的组合
- 仔细计算点以实现对称
- 添加细节(心形可以有高光曲线,雪花有复杂的分支)
要有创意和细节!好的 Slack GIF 应该看起来精致,而不是像占位图形。
可用工具
GIFBuilder(core.gif_builder)
组装帧并针对 Slack 优化:
python
builder = GIFBuilder(width=128, height=128, fps=10)
builder.add_frame(frame) # 添加 PIL Image
builder.add_frames(frames) # 添加帧列表
builder.save(out.gif, num
colors=48, optimizefor
emoji=True, removeduplicates=True)
验证器(core.validators)
检查 GIF 是否符合 Slack 要求:
python
from core.validators import validate
gif, isslack_ready
详细验证
passes, info = validate
gif(my.gif, isemoji=True, verbose=True)
快速检查
if is
slackready(my.gif):
print(准备就绪!)
缓动函数(core.easing)
实现平滑运动而非线性运动:
python
from core.easing import interpolate
进度从 0.0 到 1.0
t = i / (num_frames - 1)
应用缓动
y = interpolate(start=0, end=400, t=t, easing=ease_out)
可用:linear, easein, easeout, easeinout,
bounceout, elasticout, back_out
帧辅助工具(core.frame_composer)
常用功能的便捷函数:
python
from core.frame_composer import (
create
blankframe, # 纯色背景
create
gradientbackground, # 垂直渐变
draw_circle, # 圆形辅助
draw_text, # 简单文本渲染
draw_star # 五角星
)
动画概念
抖动/振动
通过振荡偏移对象位置:
- - 使用 math.sin() 或 math.cos() 配合帧索引
- 添加小幅随机变化以获得自然感
- 应用于 x 和/或 y 位置
脉冲/心跳
有节奏地缩放对象大小:
- - 使用 math.sin(t frequency 2 * math.pi) 实现平滑脉冲
- 心跳:两次快速脉冲后暂停(调整正弦波)
- 在基础大小的 0.8 到 1.2 倍之间缩放
弹跳
对象下落并弹起:
- - 使用 interpolate() 配合 easing=bounceout 实现落地
- 使用 easing=easein 实现下落(加速)
- 通过每帧增加 y 速度来应用重力
旋转
围绕中心旋转对象:
- - PIL:image.rotate(angle, resample=Image.BICUBIC)
- 摇摆:使用正弦波代替线性角度
淡入/淡出
逐渐出现或消失:
- - 创建 RGBA 图像,调整 alpha 通道
- 或使用 Image.blend(image1, image2, alpha)
- 淡入:alpha 从 0 到 1
- 淡出:alpha 从 1 到 0
滑动
将对象从屏幕外移动到指定位置:
- - 起始位置:在帧边界之外
- 结束位置:目标位置
- 使用 interpolate() 配合 easing=easeout 实现平滑停止
- 过冲:使用 easing=backout
缩放
缩放和定位实现缩放效果:
- - 放大:从 0.1 倍缩放到 2.0 倍,裁剪中心
- 缩小:从 2.0 倍缩放到 1.0 倍
- 可添加运动模糊增加戏剧效果(PIL 滤镜)
爆炸/粒子爆发
创建向外辐射的粒子:
- - 生成具有随机角度和速度的粒子
- 更新每个粒子:x += vx,y += vy
- 添加重力:vy += gravity_constant
- 粒子随时间淡出(减少 alpha)
优化策略
仅在要求减小文件大小时,实施以下几种方法:
- 1. 减少帧数 - 降低帧率(10 而非 20)或缩短时长
- 减少颜色数 - numcolors=48 而非 128
- 缩小尺寸 - 128x128 而非 480x480
- 去除重复帧 - save() 中设置 removeduplicates=True
- 表情符号模式 - optimizeforemoji=True 自动优化
python
表情符号的最大优化
builder.save(
emoji.gif,
num_colors=48,
optimize
foremoji=True,
remove_duplicates=True
)
设计理念
本技能提供:
- - 知识:Slack 的要求和动画概念
- 工具:GIFBuilder、验证器、缓动函数
- 灵活性:使用 PIL 基本绘图元素创建动画逻辑
本技能不提供:
- - 固定的动画模板或预制函数
- 表情符号字体渲染(跨平台不可靠)
- 内置于技能中的预置图形库
关于用户上传的说明:本技能