slack-gif-creator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSlack GIF Creator
Slack GIF制作工具包
A toolkit providing utilities and knowledge for creating animated GIFs optimized for Slack.
这是一个工具包,提供用于创建适配Slack的动画GIF的实用工具与相关知识。
Slack Requirements
Slack 要求
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
尺寸要求:
- 表情GIF:推荐128x128像素
- 消息GIF:480x480像素
参数要求:
- FPS:10-30(数值越小,文件体积越小)
- 颜色数:48-128色(颜色越少,文件体积越小)
- 时长:表情GIF需控制在3秒以内
Core Workflow
核心工作流程
python
from core.gif_builder import GIFBuilder
from PIL import Image, ImageDrawpython
from core.gif_builder import GIFBuilder
from PIL import Image, ImageDraw1. Create builder
1. 创建构建器
builder = GIFBuilder(width=128, height=128, fps=10)
builder = GIFBuilder(width=128, height=128, fps=10)
2. Generate frames
2. 生成帧
for i in range(12):
frame = Image.new('RGB', (128, 128), (240, 248, 255))
draw = ImageDraw.Draw(frame)
# Draw your animation using PIL primitives
# (circles, polygons, lines, etc.)
builder.add_frame(frame)for i in range(12):
frame = Image.new('RGB', (128, 128), (240, 248, 255))
draw = ImageDraw.Draw(frame)
# 使用PIL基础函数绘制动画
# (圆形、多边形、线条等)
builder.add_frame(frame)3. Save with optimization
3. 优化后保存
builder.save('output.gif', num_colors=48, optimize_for_emoji=True)
undefinedbuilder.save('output.gif', num_colors=48, optimize_for_emoji=True)
undefinedDrawing 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:
python
from PIL import Image
uploaded = Image.open('file.png')如果用户上传了一张图片,需判断他们的需求是:
- 直接使用(例如“把这个做成动画”、“把这个拆分成帧”)
- 作为灵感参考(例如“做一个类似这样的动图”)
使用PIL加载并处理图片:
python
from PIL import Image
uploaded = Image.open('file.png')Use directly, or just as reference for colors/style
直接使用,或仅作为色彩/风格参考
undefinedundefinedDrawing from Scratch
从零开始绘制
When drawing graphics from scratch, use PIL ImageDraw primitives:
python
from PIL import ImageDraw
draw = ImageDraw.Draw(frame)当从零开始绘制图形时,使用PIL的ImageDraw基础绘图函数:
python
from PIL import ImageDraw
draw = ImageDraw.Draw(frame)Circles/ovals
圆形/椭圆形
draw.ellipse([x1, y1, x2, y2], fill=(r, g, b), outline=(r, g, b), width=3)
draw.ellipse([x1, y1, x2, y2], fill=(r, g, b), outline=(r, g, b), width=3)
Stars, triangles, any polygon
星星、三角形及任意多边形
points = [(x1, y1), (x2, y2), (x3, y3), ...]
draw.polygon(points, 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)
Lines
线条
draw.line([(x1, y1), (x2, y2)], fill=(r, g, b), width=5)
draw.line([(x1, y1), (x2, y2)], fill=(r, g, b), width=5)
Rectangles
矩形
draw.rectangle([x1, y1, x2, y2], fill=(r, g, b), outline=(r, g, b), width=3)
**Don't use:** Emoji fonts (unreliable across platforms) or assume pre-packaged graphics exist in this skill.draw.rectangle([x1, y1, x2, y2], fill=(r, g, b), outline=(r, g, b), width=3)
**请勿使用:** 表情字体(跨平台显示效果不可靠),也不要假设本工具中存在预打包的图形资源。Making Graphics Look Good
让图形更美观
Graphics should look polished and creative, not basic. Here's how:
Use thicker lines - Always set or higher for outlines and lines. Thin lines (width=1) look choppy and amateurish.
width=2Add 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.
图形应精致且有创意,而非简陋。以下是实现方法:
使用较粗的线条 - 轮廓线和普通线条的宽度始终设置为2或更大。细线条(宽度为1)会显得粗糙且不专业。
增加视觉层次感:
- 为背景使用渐变效果(函数)
create_gradient_background - 叠加多个形状以增加复杂度(例如,在一个大星星内部绘制一个小星星)
让形状更具趣味性:
- 不要只绘制普通的圆形——添加高光、圆环或图案
- 星星可以添加发光效果(在后方绘制更大的半透明星星)
- 组合多个形状(星星+闪光、圆形+圆环)
注意色彩搭配:
- 使用鲜艳的互补色
- 增加对比度(浅色形状配深色轮廓,深色形状配浅色轮廓)
- 考虑整体构图
对于复杂形状(心形、雪花等):
- 结合使用多边形和椭圆
- 仔细计算点的位置以保证对称性
- 添加细节(心形可以加一条高光曲线,雪花可以有复杂的分支)
发挥创意!一个好的Slack GIF应该看起来精致,而不是占位符图形。
Available Utilities
可用实用工具
GIFBuilder (core.gif_builder
)
core.gif_builderGIFBuilder(core.gif_builder
模块)
core.gif_builderAssembles frames and optimizes for Slack:
python
builder = GIFBuilder(width=128, height=128, fps=10)
builder.add_frame(frame) # Add PIL Image
builder.add_frames(frames) # Add list of frames
builder.save('out.gif', num_colors=48, optimize_for_emoji=True, remove_duplicates=True)用于拼接帧并针对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, optimize_for_emoji=True, remove_duplicates=True)Validators (core.validators
)
core.validators验证器(core.validators
模块)
core.validatorsCheck if GIF meets Slack requirements:
python
from core.validators import validate_gif, is_slack_ready检查GIF是否符合Slack的要求:
python
from core.validators import validate_gif, is_slack_readyDetailed validation
详细验证
passes, info = validate_gif('my.gif', is_emoji=True, verbose=True)
passes, info = validate_gif('my.gif', is_emoji=True, verbose=True)
Quick check
快速检查
if is_slack_ready('my.gif'):
print("Ready!")
undefinedif is_slack_ready('my.gif'):
print("符合要求!")
undefinedEasing Functions (core.easing
)
core.easing缓动函数(core.easing
模块)
core.easingSmooth motion instead of linear:
python
from core.easing import interpolate实现平滑运动而非线性运动:
python
from core.easing import interpolateProgress from 0.0 to 1.0
进度从0.0到1.0
t = i / (num_frames - 1)
t = i / (num_frames - 1)
Apply easing
应用缓动效果
y = interpolate(start=0, end=400, t=t, easing='ease_out')
y = interpolate(start=0, end=400, t=t, easing='ease_out')
Available: linear, ease_in, ease_out, ease_in_out,
可用效果:linear, ease_in, ease_out, ease_in_out,
bounce_out, elastic_out, back_out
bounce_out, elastic_out, back_out
undefinedundefinedFrame Helpers (core.frame_composer
)
core.frame_composer帧辅助工具(core.frame_composer
模块)
core.frame_composerConvenience functions for common needs:
python
from core.frame_composer import (
create_blank_frame, # Solid color background
create_gradient_background, # Vertical gradient
draw_circle, # Helper for circles
draw_text, # Simple text rendering
draw_star # 5-pointed star
)满足常见需求的便捷函数:
python
from core.frame_composer import (
create_blank_frame, # 纯色背景
create_gradient_background, # 垂直渐变背景
draw_circle, # 圆形绘制助手
draw_text, # 简单文本渲染
draw_star # 五角星绘制
)Animation Concepts
动画制作理念
Shake/Vibrate
抖动/震动效果
Offset object position with oscillation:
- Use or
math.sin()with frame indexmath.cos() - Add small random variations for natural feel
- Apply to x and/or y position
通过振荡偏移对象位置:
- 使用或
math.sin()结合帧索引实现math.cos() - 添加少量随机变化以模拟自然效果
- 可应用于x轴和/或y轴位置
Pulse/Heartbeat
脉动/心跳效果
Scale object size rhythmically:
- Use for smooth pulse
math.sin(t * frequency * 2 * math.pi) - For heartbeat: two quick pulses then pause (adjust sine wave)
- Scale between 0.8 and 1.2 of base size
有节奏地缩放对象大小:
- 使用实现平滑脉动
math.sin(t * frequency * 2 * math.pi) - 心跳效果:两次快速脉动后暂停(调整正弦波)
- 在基础大小的0.8到1.2倍之间缩放
Bounce
弹跳效果
Object falls and bounces:
- Use with
interpolate()for landingeasing='bounce_out' - Use for falling (accelerating)
easing='ease_in' - Apply gravity by increasing y velocity each frame
对象下落并弹跳:
- 使用函数并设置
interpolate()实现落地效果easing='bounce_out' - 使用实现下落(加速)效果
easing='ease_in' - 通过每帧增加y轴速度来模拟重力
Spin/Rotate
旋转效果
Rotate object around center:
- PIL:
image.rotate(angle, resample=Image.BICUBIC) - For wobble: use sine wave for angle instead of linear
围绕中心旋转对象:
- PIL:
image.rotate(angle, resample=Image.BICUBIC) - 摇摆效果:使用正弦波控制角度而非线性变化
Fade In/Out
淡入/淡出效果
Gradually appear or disappear:
- Create RGBA image, adjust alpha channel
- Or use
Image.blend(image1, image2, alpha) - Fade in: alpha from 0 to 1
- Fade out: alpha from 1 to 0
逐渐出现或消失:
- 创建RGBA图片,调整alpha通道
- 或使用函数
Image.blend(image1, image2, alpha) - 淡入:alpha值从0到1
- 淡出:alpha值从1到0
Slide
滑动效果
Move object from off-screen to position:
- Start position: outside frame bounds
- End position: target location
- Use with
interpolate()for smooth stopeasing='ease_out' - For overshoot: use
easing='back_out'
对象从屏幕外移动到目标位置:
- 起始位置:屏幕边界外
- 结束位置:目标位置
- 使用函数并设置
interpolate()实现平滑停止easing='ease_out' - 过冲效果:使用
easing='back_out'
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)
通过缩放和定位实现变焦效果:
- 放大:从0.1倍缩放到2.0倍,裁剪中心区域
- 缩小:从2.0倍缩放到1.0倍
- 可添加运动模糊以增强戏剧性(使用PIL滤镜)
Explode/Particle Burst
爆炸/粒子爆发效果
Create particles radiating outward:
- Generate particles with random angles and velocities
- Update each particle: ,
x += vxy += vy - Add gravity:
vy += gravity_constant - Fade out particles over time (reduce alpha)
创建向外辐射的粒子:
- 生成带有随机角度和速度的粒子
- 更新每个粒子的位置:,
x += vxy += vy - 添加重力:
vy += gravity_constant - 随时间淡出粒子(降低alpha值)
Optimization Strategies
优化策略
Only when asked to make the file size smaller, implement a few of the following methods:
- Fewer frames - Lower FPS (10 instead of 20) or shorter duration
- Fewer colors - instead of 128
num_colors=48 - Smaller dimensions - 128x128 instead of 480x480
- Remove duplicates - in save()
remove_duplicates=True - Emoji mode - auto-optimizes
optimize_for_emoji=True
python
undefined仅当用户要求缩小文件体积时,才采用以下部分方法:
- 减少帧数 - 降低FPS(从20改为10)或缩短时长
- 减少颜色数 - 设置而非128
num_colors=48 - 缩小尺寸 - 使用128x128像素而非480x480
- 移除重复帧 - 在方法中设置
save()remove_duplicates=True - 表情模式 - 设置以自动优化
optimize_for_emoji=True
python
undefinedMaximum optimization for emoji
表情GIF最大化优化
builder.save(
'emoji.gif',
num_colors=48,
optimize_for_emoji=True,
remove_duplicates=True
)
undefinedbuilder.save(
'emoji.gif',
num_colors=48,
optimize_for_emoji=True,
remove_duplicates=True
)
undefinedPhilosophy
设计理念
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.
本工具提供:
- 知识:Slack的要求和动画制作理念
- 实用工具:GIFBuilder、验证器、缓动函数
- 灵活性:使用PIL基础函数创建动画逻辑
本工具不提供:
- 固定的动画模板或预制函数
- 表情字体渲染(跨平台显示不可靠)
- 内置的预打包图形资源库
关于用户上传内容的说明:本工具不包含预制图形资源,但如果用户上传了图片,可使用PIL加载并处理——根据用户的请求判断是直接使用该图片还是仅作为灵感参考。
发挥创意!将多种效果组合(例如弹跳+旋转、脉动+滑动等),充分利用PIL的全部功能。
Dependencies
依赖项
bash
pip install pillow imageio numpybash
pip install pillow imageio numpy