README
🚀 Imagician - MCP 图像编辑器
Imagician 是一个基于模型上下文协议(MCP)的服务器,可进行全面的图像编辑操作,包括调整大小、格式转换、裁剪、压缩等。
🚀 快速开始
Imagician 是一款强大的图像编辑工具,支持多种图像编辑操作。你可以通过以下步骤开始使用它。
✨ 主要特性
- 调整大小:通过各种适配选项更改图像尺寸。
- 格式转换:在 JPEG、PNG、WebP 和 AVIF 之间进行转换。
- 裁剪:从图像中提取特定区域。
- 压缩:通过质量控制减小文件大小。
- 旋转:将图像旋转任意角度。
- 翻转:水平或垂直镜像图像。
- 批量处理:从单张图像生成多种尺寸。
- 元数据:提取图像信息和属性。
📦 安装指南
从 npm 安装
npm install -g @flowy11/imagician
从源代码安装
git clone https://github.com/flowy11/imagician.git
cd imagician
npm install
npm run build
💻 使用示例
在 Claude Code 中使用
将以下内容添加到你的 Claude Code 配置文件(~/.config/claude/config/settings/mcp-servers.json)中:
{
"imagician": {
"command": "npx",
"args": ["-y", "@flowy11/imagician"]
}
}
在 Cursor 中使用
将以下内容添加到你的 Cursor 配置文件(~/.cursor/mcp_settings.json)中:
{
"mcpServers": {
"imagician": {
"command": "npx",
"args": ["-y", "@flowy11/imagician"]
}
}
}
在 Claude Desktop 中使用
快速使用 npx 设置(推荐)
将以下内容添加到你的 Claude Desktop 配置文件(~/Library/Application Support/Claude/claude_desktop_config.json)中:
{
"mcpServers": {
"imagician": {
"command": "npx",
"args": ["-y", "@flowy11/imagician"]
}
}
}
如果你通过 npm 全局安装
{
"mcpServers": {
"imagician": {
"command": "imagician"
}
}
}
如果你从源代码安装
{
"mcpServers": {
"imagician": {
"command": "node",
"args": ["/path/to/imagician/dist/index.js"]
}
}
}
可用工具
resize_image
将图像调整为指定尺寸,并提供多种适配选项。
参数:
- inputPath: 输入图像的路径
- outputPath: 保存调整大小后图像的路径
- width: 目标宽度(像素,可选)
- height: 目标高度(像素,可选)
- fit: 调整大小的方式(cover, contain, fill, inside, outside)
- preserveAspectRatio: 保持宽高比(默认值: true)
convert_format
在图像格式之间进行转换,并可控制质量。
参数:
- inputPath: 输入图像的路径
- outputPath: 保存转换后图像的路径
- format: 目标格式(jpeg, png, webp, avif)
- quality: 有损格式的质量(1 - 100,默认值: 80)
crop_image
从图像中提取特定区域。
参数:
- inputPath: 输入图像的路径
- outputPath: 保存裁剪后图像的路径
- left: 左偏移量(像素)
- top: 上偏移量(像素)
- width: 裁剪区域的宽度
- height: 裁剪区域的高度
compress_image
通过质量设置减小图像文件大小。
参数:
- inputPath: 输入图像的路径
- outputPath: 保存压缩后图像的路径
- quality: 压缩质量(1 - 100,默认值: 80)
- progressive: 对 JPEG 使用渐进式编码(默认值: true)
rotate_image
将图像旋转任意角度。
参数:
- inputPath: 输入图像的路径
- outputPath: 保存旋转后图像的路径
- angle: 旋转角度(度,正值表示顺时针)
- background: 暴露区域的背景颜色(默认值: #000000)
flip_image
水平或垂直镜像图像。
参数:
- inputPath: 输入图像的路径
- outputPath: 保存翻转后图像的路径
- direction: 翻转方向(horizontal, vertical, both)
get_image_info
提取图像的元数据和信息。
参数:
- inputPath: 图像文件的路径
返回值: 格式、尺寸、色彩空间、文件大小等。
batch_resize
从一张图像生成多种尺寸(非常适合响应式图像)。
参数:
- inputPath: 输入图像的路径
- outputDir: 保存调整大小后图像的目录
- sizes: {width, height?, suffix} 数组
- format: 所有尺寸的输出格式(可选)
在 Claude 中的使用示例
"请将 image.jpg 调整为 800x600 像素"
"将 photo.png 转换为 WebP 格式,质量为 90%"
"从 (100, 100) 开始裁剪 avatar.jpg,大小为 200x200"
"生成缩略图尺寸:宽 150px、300px 和 600px"
🔧 技术细节
开发
# 安装依赖
npm install
# 构建 TypeScript
npm run build
# 在开发模式下运行
npm run dev
📄 许可证
本项目采用 MIT 许可证。
Scan to join WeChat group