技能图谱SKILLSGROVE
技能图谱/视频制作/LeastBit/Claude_skills_zh-CN/slack-gif-creator

slack-gif-creator

安装

$npx skills add https://github.com/LeastBit/Claude_skills_zh-CN --skill slack-gif-creator
$git clone --depth 1 https://github.com/LeastBit/Claude_skills_zh-CN.git /tmp/Claude_skills_zh-CN && mkdir -p ~/.claude/skills && cp -r /tmp/Claude_skills_zh-CN/skills/slack-gif-creator ~/.claude/skills/slack-gif-creator
请帮我安装这个 Agent Skill:https://github.com/LeastBit/Claude_skills_zh-CN/tree/1ab29163cbd3cfaf873a880db48f097b032a2c02/skills/slack-gif-creator ,先阅读它的 SKILL.md 和脚本,确认安全后再安装到我的技能目录。

简介

原文描述 · Apache-2.0用于创建针对 Slack 优化的动画 GIF 的知识和工具集。提供约束条件、验证工具和动画概念。当用户请求为 Slack 创建动画 GIF 时使用,例如"为 Slack 制作一个 X 做 Y 的 GIF"。
以下 SKILL.md 内容转载自 LeastBit/Claude_skills_zh-CN(提交 1ab2916),依据 Apache-2.0 许可证转载正文(文字未改动;仅省略文件头元数据、将图片显示为链接,超长内容会截断);版权归 owner or entity authorized by 所有。许可证:skills/slack-gif-creator/LICENSE.txt。仅展示说明文件,附带脚本请在原仓库查看。

Slack GIF 创建器

一个提供工具和知识的工具包,用于创建针对 Slack 优化的动画 GIF。

Slack 要求

尺寸:

  • 表情符号 GIF:128x128(推荐)
  • 消息 GIF:480x480

参数:

  • FPS:10-30(较低的值可减小文件大小)
  • 颜色:48-128(颜色越少 = 文件越小)
  • 时长:表情符号 GIF 应控制在 3 秒以内

核心工作流程

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, optimize_for_emoji=True)

绘制图形

处理用户上传的图片

如果用户上传了图片,请考虑他们想要:

  • 直接使用(例如,"给这个添加动画","把这个分成帧")
  • 作为灵感参考(例如,"制作类似这样的东西")

使用 PIL 加载和处理图片:

from PIL import Image

uploaded = Image.open('file.png')
# 直接使用,或仅作为颜色/风格的参考

从零开始绘制

从零开始绘制图形时,使用 PIL ImageDraw 基础图形:

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)

不要使用: Emoji 字体(在不同平台上表现不一致)或假设此技能中有预打包的图形。

让图形更美观

图形应该看起来精致有创意,而不是简陋。以下是方法:

使用较粗的线条 - 轮廓和线条始终设置 width=2 或更高。细线(width=1)看起来粗糙且业余。

添加视觉深度:

  • 使用渐变背景(create_gradient_background)
  • 叠加多个形状以增加复杂度(例如,一个星形内部套一个小星形)

让形状更有趣:

  • 不要只画一个普通的圆 - 添加高光、光环或图案
  • 星形可以有光晕(在后面绘制更大的半透明版本)
  • 组合多个形状(星形 + 闪光、圆形 + 光环)

注意颜色搭配:

  • 使用鲜艳的互补色
  • 添加对比度(浅色形状用深色轮廓,深色形状用浅色轮廓)
  • 考虑整体构图

对于复杂形状(心形、雪花等):

  • 使用多边形和椭圆的组合
  • 仔细计算点位以保持对称
  • 添加细节(心形可以有高光曲线,雪花有精细的分支)

要有创意和注重细节!好的 Slack GIF 应该看起来精致,而不是像占位图形。

可用工具

GIFBuilder (core.gif_builder)

组装帧并为 Slack 优化:

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)

验证器 (core.validators)

检查 GIF 是否符合 Slack 要求:

from core.validators import validate_gif, is_slack_ready

# 详细验证
passes, info = validate_gif('my.gif', is_emoji=True, verbose=True)

# 快速检查
if is_slack_ready('my.gif'):
    print("准备就绪!")

缓动函数 (core.easing)

平滑运动而非线性:

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, ease_in, ease_out, ease_in_out,
#      bounce_out, elastic_out, back_out

帧辅助函数 (core.frame_composer)

常用需求的便捷函数:

from core.frame_composer import (
    create_blank_frame,         # 纯色背景
    create_gradient_background,  # 垂直渐变
    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='bounce_out' 实现落地效果
  • 使用 easing='ease_in' 实现下落(加速)效果
  • 通过每帧增加 y 速度来模拟重力

旋转

围绕中心旋转对象:

  • PIL:image.rotate(angle, resample=Image.BICUBIC)
  • 对于摇摆效果:使用正弦波控制角度而非线性变化

淡入/淡出

逐渐出现或消失:

  • 创建 RGBA 图像,调整 alpha 通道
  • 或使用 Image.blend(image1, image2, alpha)
  • 淡入:alpha 从 0 到 1
  • 淡出:alpha 从 1 到 0

滑动

将对象从屏幕外移动到指定位置:

  • 起始位置:帧边界外
  • 结束位置:目标位置
  • 使用 interpolate() 配合 easing='ease_out' 实现平滑停止
  • 对于超越效果:使用 easing='back_out'

缩放

缩放和定位以实现缩放效果:

  • 放大:从 0.1 缩放到 2.0,裁剪中心
  • 缩小:从 2.0 缩放到 1.0
  • 可添加运动模糊增加戏剧效果(PIL 滤镜)

爆炸/粒子迸发

创建向外辐射的粒子:

  • 生成具有随机角度和速度的粒子
  • 更新每个粒子:x += vx,y += vy
  • 添加重力:vy += gravity_constant
  • 随时间淡出粒子(降低 alpha)

优化策略

仅在被要求减小文件大小时,实施以下几种方法:

  1. 减少帧数 - 降低 FPS(用 10 而不是 20)或缩短时长
  2. 减少颜色 - num_colors=48 而不是 128
  3. 减小尺寸 - 128x128 而不是 480x480
  4. 移除重复帧 - 在 save() 中使用 remove_duplicates=True
  5. 表情符号模式 - optimize_for_emoji=True 自动优化
# 表情符号最大优化
builder.save(
    'emoji.gif',
    num_colors=48,
    optimize_for_emoji=True,
    remove_duplicates=True
)

设计理念

本技能提供:

  • 知识:Slack 的要求和动画概念
  • 工具:GIFBuilder、验证器、缓动函数
  • 灵活性:使用 PIL 基础图形创建动画逻辑

本技能不提供:

  • 僵化的动画模板或预制函数
  • Emoji 字体渲染(在不同平台上表现不一致)
  • 内置于技能中的预打包图形库

关于用户上传的说明:本技能不包含预构建的图形,但如果用户上传了图片,请使用 PIL 加载和处理它 - 根据他们的请求判断是直接使用还是仅作为灵感参考。

发挥创意!组合各种概念(弹跳 + 旋转、脉动 + 滑动等)并充分利用 PIL 的全部功能。

依赖项

pip install pillow imageio numpy
查看许可证全文(Apache-2.0)
                                 Apache License
                           Version 2.0, January 2004
                        http://www.apache.org/licenses/

   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

   1. Definitions.

      "License" shall mean the terms and conditions for use, reproduction,
      and distribution as defined by Sections 1 through 9 of this document.

      "Licensor" shall mean the copyright owner or entity authorized by
      the copyright owner that is granting the License.

      "Legal Entity" shall mean the union of the acting entity and all
      other entities that control, are controlled by, or are under common
      control with that entity. For the purposes of this definition,
      "control" means (i) the power, direct or indirect, to cause the
      direction or management of such entity, whether by contract or
      otherwise, or (ii) ownership of fifty percent (50%) or more of the
      outstanding shares, or (iii) beneficial ownership of such entity.

      "You" (or "Your") shall mean an individual or Legal Entity
      exercising permissions granted by this License.

      "Source" form shall mean the preferred form for making modifications,
      including but not limited to software source code, documentation
      source, and configuration files.

      "Object" form shall mean any form resulting from mechanical
      transformation or translation of a Source form, including but
      not limited to compiled object code, generated documentation,
      and conversions to other media types.

      "Work" shall mean the work of authorship, whether in Source or
      Object form, made available under the License, as indicated by a
      copyright notice that is included in or attached to the work
      (an example is provided in the Appendix below).

      "Derivative Works" shall mean any work, whether in Source or Object
      form, that is based on (or derived from) the Work and for which the
      editorial revisions, annotations, elaborations, or other modifications
      represent, as a whole, an original work of authorship. For the purposes
      of this License, Derivative Works shall not include works that remain
      separable from, or merely link (or bind by name) to the interfaces of,
      the Work and Derivative Works thereof.

      "Contribution" shall mean any work of authorship, including
      the original version of the Work and any modifications or additions
      to that Work or Derivative Works thereof, that is intentionally
      submitted to Licensor for inclusion in the Work by the copyright owner
      or by an individual or Legal Entity authorized to submit on behalf of
      the copyright owner. For the purposes of this definition, "submitted"
      means any form of electronic, verbal, or written communication sent
      to the Licensor or its representatives, including but not limited to
      communication on electronic mailing lists, source code control systems,
      and issue tracking systems that are managed by, or on behalf of, the
      Licensor for the purpose of discussing and improving the Work, but
      excluding communication that is conspicuously marked or otherwise
      designated in writing by the copyright owner as "Not a Contribution."

      "Contributor" shall mean Licensor and any individual or Legal Entity
      on behalf of whom a Contribution has been received by Licensor and
      subsequently incorporated within the Work.

   2. Grant of Copyright License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      copyright license to reproduce, prepare Derivative Works of,
      publicly display, publicly perform, sublicense, and distribute the
      Work and such Derivative Works in Source or Object form.

   3. Grant of Patent License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      (except as stated in this section) patent license to make, have made,
      use, offer to sell, sell, import, and otherwise transfer the Work,
      where such license applies only to those patent claims licensable
      by such Contributor that are necessarily infringed by their
      Contribution(s) alone or by combination of their Contribution(s)
      with the Work to which such Contribution(s) was submitted. If You
      institute patent litigation against any entity (including a
      cross-claim or counterclaim in a lawsuit) alleging that the Work
      or a Contribution incorporated within the Work constitutes direct
      or contributory patent infringement, then any patent licenses
      granted to You under this License for that Work shall terminate
      as of the date such litigation is filed.

   4. Redistribution. You may reproduce and distribute copies of the
      Work or Derivative Works thereof in any medium, with or without
      modifications, and in Source or Object form, provided that You
      meet the following conditions:

      (a) You must give any other recipients of the Work or
          Derivative Works a copy of this License; and

      (b) You must cause any modified files to carry prominent notices
          stating that You changed the files; and

      (c) You must retain, in the Source form of any Derivative Works
          that You distribute, all copyright, patent, trademark, and
          attribution notices from the Source form of the Work,
          excluding those notices that do not pertain to any part of
          the Derivative Works; and

      (d) If the Work includes a "NOTICE" text file as part of its
          distribution, then any Derivative Works that You distribute must
          include a readable copy of the attribution notices contained
          within such NOTICE file, excluding those notices that do not
          pertain to any part of the Derivative Works, in at least one
          of the following places: within a NOTICE text file distributed
          as part of the Derivative Works; within the Source form or
          documentation, if provided along with the Derivative Works; or,
          within a display generated by the Derivative Works, if and
          wherever such third-party notices normally appear. The contents
          of the NOTICE file are for informational purposes only and
          do not modify the License. You may add Your own attribution
          notices within Derivative Works that You distribute, alongside
          or as an addendum to the NOTICE text from the Work, provided
          that such additional attribution notices cannot be construed
          as modifying the License.

      You may add Your own copyright statement to Your modifications and
      may provide additional or different license terms and conditions
      for use, reproduction, or distribution of Your modifications, or
      for any such Derivative Works as a whole, provided Your use,
      reproduction, and distribution of the Work otherwise complies with
      the conditions stated in this License.

   5. Submission of Contributions. Unless You explicitly state otherwise,
      any Contribution intentionally submitted for inclusion in the Work
      by You to the Licensor shall be under the terms and conditions of
      this License, without any additional terms or conditions.
      Notwithstanding the above, nothing herein shall supersede or modify
      the terms of any separate license agreement you may have executed
      with Licensor regarding such Contributions.

   6. Trademarks. This License does not grant permission to use the trade
      names, trademarks, service marks, or product names of the Licensor,
      except as required for reasonable and customary use in describing the
      origin of the Work and reproducing the content of the NOTICE file.

   7. Disclaimer of Warranty. Unless required by applicable law or
      agreed to in writing, Licensor provides the Work (and each
      Contributor provides its Contributions) on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
      implied, including, without limitation, any warranties or conditions
      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
      PARTICULAR PURPOSE. You are solely responsible for determining the
      appropriateness of using or redistributing the Work and assume any
      risks associated with Your exercise of permissions under this License.

   8. Limitation of Liability. In no event and under no legal theory,
      whether in tort (including negligence), contract, or otherwise,
      unless required by applicable law (such as deliberate and grossly
      negligent acts) or agreed to in writing, shall any Contributor be
      liable to You for damages, including any direct, indirect, special,
      incidental, or consequential damages of any character arising as a
      result of this License or out of the use or inability to use the
      Work (including but not limited to damages for loss of goodwill,
      work stoppage, computer failure or malfunction, or any and all
      other commercial damages or losses), even if such Contributor
      has been advised of the possibility of such damages.

   9. Accepting Warranty or Additional Liability. While redistributing
      the Work or Derivative Works thereof, You may choose to offer,
      and charge a fee for, acceptance of support, warranty, indemnity,
      or other liability obligations and/or rights consistent with this
      License. However, in accepting such obligations, You may act only
      on Your own behalf and on Your sole responsibility, not on behalf
      of any other Contributor, and only if You agree to indemnify,
      defend, and hold each Contributor harmless for any liability
      incurred by, or claims asserted against, such Contributor by reason
      of your accepting any such warranty or additional liability.

   END OF TERMS AND CONDITIONS

   APPENDIX: How to apply the Apache License to your work.

      To apply the Apache License to your work, attach the following
      boilerplate notice, with the fields enclosed by brackets "[]"
      replaced with your own identifying information. (Don't include
      the brackets!)  The text should be enclosed in the appropriate
      comment syntax for the file format. We also recommend that a
      file or class name and description of purpose be included on the
      same "printed page" as the copyright notice for easier
      identification within third-party archives.

   Copyright [yyyy] [name of copyright owner]

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.