# Image Cropper

> 图像裁剪工具，支持保持画面中心的智能裁剪。使用场景：（1）微信公众号封面裁剪（2.35:1）（2）社交媒体正方形裁剪（1:1）（3）批量处理图片尺寸（4）各种社交媒体预设尺寸（微信、微博、Instagram等）。当用户需要"裁剪图片"、"调整图片尺寸"、"生成正方形图片"、"微信封面裁剪"时触发此skill。

- **Type:** Skill
- **Install:** `agentstack add skill-hhhh124hhhh-skillmate-image-cropper`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [hhhh124hhhh](https://agentstack.voostack.com/s/hhhh124hhhh)
- **Installs:** 0
- **Category:** [Content & Media](https://agentstack.voostack.com/c/content-and-media)
- **Latest version:** 0.1.0
- **License:** Apache-2.0
- **Upstream author:** [hhhh124hhhh](https://github.com/hhhh124hhhh)
- **Source:** https://github.com/hhhh124hhhh/SkillMate/tree/main/resources/skills/image-cropper

## Install

```sh
agentstack add skill-hhhh124hhhh-skillmate-image-cropper
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# 图像裁剪工具

智能图像裁剪工具，支持保持画面中心的精准裁剪，专为社交媒体和内容创作优化。

## 🚀 快速开始

### 命令行使用

```bash
# 单张裁剪
python scripts/crop_image.py input.jpg --size 900x383 --output output.jpg

# 使用预设尺寸
python scripts/crop_image.py input.jpg --preset wechat-cover --output output.jpg

# 批量裁剪
python scripts/batch_crop.py folder/ --size 900x383 --output cropped_folder/
```

### Python调用

```python
from image_cropper.scripts.crop_image import crop_to_center

# 裁剪为指定尺寸
crop_to_center("input.jpg", "output.jpg", width=900, height=383)

# 使用预设尺寸
crop_to_center("input.jpg", "output.jpg", preset="wechat-cover")

# 批量裁剪
from image_cropper.scripts.batch_crop import batch_crop
batch_crop("folder/", "output_folder/", size="900x383")
```

## 📏 预设尺寸

### 微信公众号

- `wechat-cover`: 900x383（2.35:1，公众号封面）
- `wechat-share`: 900x900（1:1，分享卡片）
- `wechat-banner`: 1080x460（2.35:1，高清封面）

### 社交媒体

- `instagram`: 1080x1080（1:1，Instagram/微博）
- `twitter`: 1200x675（16:9，Twitter横版）
- `linkedin`: 1200x627（1.91:1，LinkedIn）

### 文章配图

- `article-16-9`: 1792x1024（16:9，横版配图）
- `article-4-3`: 1024x768（4:3，标准配图）
- `article-1-1`: 1024x1024（1:1，正方形配图）

## 🎯 使用场景

### 场景1：微信公众号封面裁剪

**需求**：生成一张同时适合头条展示和朋友圈分享的封面

**解决方案**：
```bash
# 生成2.35:1封面（900x383）
python scripts/crop_image.py original.jpg --preset wechat-cover --output cover.jpg

# 同时生成1:1测试版本（验证分享效果）
python scripts/crop_image.py original.jpg --preset wechat-share --output test_1to1.jpg
```

**关键原则**：
- 所有关键内容必须在中心60%区域
- 确保裁剪为1:1后文字依然完整
- 避免在边缘放置重要元素

### 场景2：批量处理配图

**需求**：将一个文件夹的所有图片统一裁剪为16:9

**解决方案**：
```bash
python scripts/batch_crop.py raw_images/ --preset article-16-9 --output cropped_images/
```

### 场景3：Instagram正方形裁剪

**需求**：将横版照片裁剪为正方形

**解决方案**：
```bash
python scripts/crop_image.py photo.jpg --preset instagram --output photo_square.jpg
```

## 🔧 参数说明

### 单张裁剪（crop_image.py）

| 参数 | 说明 | 示例 |
|------|------|------|
| `input` | 输入图片路径（必需） | `photo.jpg` |
| `--size` | 输出尺寸（宽x高） | `900x383` |
| `--preset` | 使用预设尺寸 | `wechat-cover` |
| `--output` | 输出路径（必需） | `output.jpg` |
| `--quality` | JPEG质量（1-100，默认95） | `95` |

**注意**：`--size` 和 `--preset` 二选一，优先使用 `--preset`

### 批量裁剪（batch_crop.py）

| 参数 | 说明 | 示例 |
|------|------|------|
| `input_dir` | 输入文件夹路径（必需） | `images/` |
| `--size` | 输出尺寸 | `900x383` |
| `--preset` | 使用预设尺寸 | `wechat-cover` |
| `--output` | 输出文件夹路径（必需） | `cropped/` |
| `--pattern` | 文件匹配模式（默认*.jpg） | `*.png` |

## 💡 最佳实践

### 1. 安全区域设计

对于可能被裁剪的场景（如微信封面），设计时遵循：

```
画面布局：
[边缘20%] [中心60%安全区] [边缘20%]
```

**关键内容**：只放在中心60%区域
**装饰元素**：可以放在边缘

### 2. 裁剪前测试

在正式使用前，先测试1:1裁剪效果：

```bash
# 生成多个测试版本
python scripts/crop_image.py original.jpg --size 900x900 --output test_1to1.jpg
python scripts/crop_image.py original.jpg --size 900x383 --output test_cover.jpg
```

检查：
- ✅ 文字是否完整
- ✅ 关键元素是否在中心
- ✅ 裁剪后效果是否满意

### 3. 批量处理技巧

批量处理时，建议：
- 先用1-2张图片测试效果
- 确认满意后再批量处理
- 保留原始文件备份

## 📊 依赖安装

```bash
pip install pillow
```

## 🛠️ 故障排查

### 常见问题

**Q1：提示"PIL not available"**

```bash
# 安装Pillow库
pip install pillow
```

**Q2：裁剪后图片变形**

原因：指定尺寸比例与原图不一致
解决：本工具保持原图比例中心裁剪，不会变形

**Q3：裁剪位置不符合预期**

原因：本工具默认保持画面中心裁剪
解决：如需自定义裁剪位置，可使用专业图像编辑工具

**Q4：批量裁剪时某些图片失败**

原因：图片格式不支持或文件损坏
解决：检查文件格式，支持JPG、PNG等常见格式

## 📚 参考资源

- **预设尺寸列表**：`references/preset-sizes.md`
- **使用示例**：见上方各场景说明
- **技术文档**：Pillow官方文档 https://pillow.readthedocs.io/

---

**最后更新**：2026-01-11
**Skill版本**：v1.0
**依赖**：Pillow >= 8.0.0

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [hhhh124hhhh](https://github.com/hhhh124hhhh)
- **Source:** [hhhh124hhhh/SkillMate](https://github.com/hhhh124hhhh/SkillMate)
- **License:** Apache-2.0

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-hhhh124hhhh-skillmate-image-cropper
- Seller: https://agentstack.voostack.com/s/hhhh124hhhh
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
