SuperAPI AI Directory

gif-splitter

General & other

View repository

Updated 10-15 22:38

About this skill

GIF Animation Splitting Tool

Overview

This skill is used to solve the "image frame count exceeds 300 frames" limit problem encountered when uploading GIFs to platforms such as WeChat Official Accounts. It automatically detects the GIF frame count and intelligently splits GIFs that exceed the limit into multiple smaller files that meet the requirements.

Use Cases

This skill is triggered when users encounter the following situations:

  • Uploading a GIF to WeChat Official Accounts prompts "frame count exceeds 300 frames"
  • Need to split a large GIF into multiple small GIFs
  • Need to check the frame count information of a GIF file
  • Need to ensure each file does not exceed a specified size after splitting the GIF

Quick Start

When users need to split a GIF, run the following script:

# 切分单个GIF文件(默认最大280帧)
python3 ~/.claude/skills/jiamu-skills/gif-splitter/scripts/split_gif.py "GIF文件路径"

# 切分文件夹中所有GIF
python3 ~/.claude/skills/jiamu-skills/gif-splitter/scripts/split_gif.py "文件夹路径"

Output directory: the split_output/ folder under the directory where the original file is located

Dependencies

Install Pillow

pip3 install Pillow

Verify installation

python3 -c "from PIL import Image; print('Pillow 安装成功')"

Usage Commands

Basic Usage

# 切分单个文件
python3 scripts/split_gif.py "动图.gif"

# 切分整个文件夹
python3 scripts/split_gif.py ~/Desktop/gif文件夹/

Custom Parameters

# 指定最大帧数(默认280帧,微信限制300帧)
python3 scripts/split_gif.py "动图.gif" --max-frames 200

# 指定输出目录
python3 scripts/split_gif.py "动图.gif" -o ~/Desktop/output

# 仅查看GIF信息,不切分
python3 scripts/split_gif.py "动图.gif" --info

# 组合使用
python3 scripts/split_gif.py ~/gifs/ --max-frames 250 -o ~/output --info

Parameter Description

Parameter Description Default Value
path GIF file or folder path Required
--max-frames, -m Maximum frame count per output file 280
-o, --output Output directory The split_output/
--info Only display GIF information, do not perform splitting False

How It Works

Splitting Algorithm

  1. Read GIF: Use the Pillow library to read all frames of the GIF and the duration of each frame
  2. Calculate segments: Based on the total frame count and the maximum frame count limit, calculate the number of files to split into
  3. Distribute evenly: Distribute frames evenly across output files to avoid the last file having too few frames
  4. Save output: Preserve the original frame rate and loop settings, and generate optimized GIF files

Example

Original file:演示动画.gif(740 frames, 5.7MB)

Splitting result:

演示动画_第1部分.gif  (247帧, 约2MB)
演示动画_第2部分.gif  (247帧, 约2MB)
演示动画_第3部分.gif  (246帧, 约2MB)

Platform Limits Reference

Platform Frame Count Limit File Size Limit Recommended --max-frames
WeChat Official Accounts 300 frames 10MB 280 (default)
WeChat Chat No explicit limit 25MB As needed
Weibo No explicit limit 20MB As needed

FAQ

Why is the split file larger than the original file?

This is normal. Reasons:

  1. The original GIF may have used global palette optimization
  2. Each file after splitting requires an independent palette
  3. Inter-frame compression effectiveness is reduced

Solution: appropriately increase --max-frames to reduce the number of splits

Why did the animation speed change after splitting?

The script preserves the original frame rate. If the speed appears abnormal, it may be because the original GIF's frame timing information is incomplete.

How to only view GIF information without splitting?

python3 scripts/split_gif.py "动图.gif" --info

Example output:

文件: 演示动画.gif
帧数: 740 帧
大小: 5.70 MB
尺寸: 800x600
状态: 需要切分(超过 280 帧)

Output Format

Output file naming rule:{原文件名}_第{序号}部分.gif

Example:

  • 演示.gif → 演示_第1部分.gif, 演示_第2部分.gif

Technical details

  • Library dependencies:Pillow (PIL)
  • Python version:3.6+
  • Supported formats: GIF (animated/static)
  • Output optimization: enable GIF optimized compression