图片优化服务

MinifyPics MCP是一个用于Cline的模型上下文协议服务器,提供高效的图像优化功能,支持多种格式并保持视觉质量。

  • by chileung69
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 chileung69/minifypics

使用说明

MinifyPics MCP

Cline的模型上下文协议(MCP)服务器,在保持质量的同时实现图像优化。此MCP与MinifyPics API集成,可在不造成重大质量损失的情况下提供高效的图像压缩。

🌟 特性

  • 高效图像优化:在保持视觉质量的同时减小图像文件大小
  • 支持多种格式:适用于JPEG、PNG、GIF和WebP图像
  • 简单集成:易于安装并与Cline集成
  • 详细统计:获取有关尺寸减小和节省的全面信息
  • 灵活的输出选项:将优化后的图像保存到自定义位置或替换原始图像
  • 批处理:按顺序处理多个图像

📋 需求

🚀 安装

自动安装

最简单的安装方法是使用提供的安装脚本:

  1. 克隆此存储库:

    git clone https://github.com/yourusername/minifypics-mcp.git
    cd minifypics-mcp
    
  2. 运行安装脚本:

    node install.js
    
  3. 按照提示操作:

    • 安装依赖项
    • 配置API密钥
    • 设置输出目录(可选)
    • 配置日志记录级别

该脚本将提供与Cline集成和测试安装的说明。

手动安装

如果您更喜欢手动安装:

  1. 克隆此存储库:

    git clone https://github.com/yourusername/minifypics-mcp.git
    cd minifypics-mcp
    
  2. 安装依赖项:

    npm install
    
  3. 复制示例配置文件:

    cp config.example.js config.js
    
  4. 编辑 config.js 添加API密钥并自定义设置。

  5. 启动服务器:

    npm start
    

🔌 与Cline整合

有两种方法可以将此服务器与Cline集成:

选项1:Direct Express服务器集成

此选项直接启动Express服务器:

{
  "mcpServers": {
    "minifypics": {
      "command": "node",
      "args": ["/absolute/path/to/minifypics/src/index.js"],
      "env": {
        "PORT": "3000",
        "API_KEY": "your-api-key-here"
      },
      "disabled": false
    }
  }
}

替换 /absolute/path/to/minifypics 使用系统上此存储库的实际绝对路径。安装脚本将为您提供正确的路径。

选项2:MCP包装器集成(推荐)

此选项使用MCP包装器,它与Cline的MCP协议提供了更无缝的集成:

{
  "mcpServers": {
    "minifypics": {
      "command": "node",
      "args": ["-e", "require('/absolute/path/to/minifypics/mcp-wrapper.js')"],
      "env": {
        "API_KEY": "your-api-key-here"
      },
      "disabled": false
    }
  }
}

替换 /absolute/path/to/minifypics 使用系统上此存储库的实际绝对路径。安装脚本将为您提供正确的路径。

🛠️ 用法

一旦与Cline集成,您就可以使用 minify_image 工具直接:

<use_mcp_tool>
<server_name>minifypics</server_name>
<tool_name>minify_image</tool_name>
<arguments>
{
  "imagePath": "/path/to/your/image.jpg",
  "outputPath": "/path/to/output/image.jpg",
  "replaceOriginal": false
}
</arguments>
</use_mcp_tool>

参数

  • imagePath (必需):要缩小的图像文件的路径
  • outputPath (可选):应保存缩小图像的路径。如果没有提供,压缩后的图像将保存在与原始图像相同的目录中,并在文件名中添加“-minified”。
  • replaceOriginal (可选):布尔值,指示是否用缩小版本替换原始图像。默认值为 false。如果设置为 true,只有缩小版本较小时,才会替换原始图像。

响应

该工具返回具有以下属性的对象:

{
  "success": true,
  "originalPath": "/path/to/your/image.jpg",
  "minifiedPath": "/path/to/save/minified-image.jpg",
  "originalSize": 1024000,
  "minifiedSize": 512000,
  "savingsPercent": 50.00,
  "replaced": false,
  "message": "Image successfully minified and saved to: /path/to/save/minified-image.jpg"
}

🧪 测试

下载测试图像

node download-test-image.js

测试Express服务器

node test.js [path-to-image] [--replace]

选项:

  • [path-to-image]:要缩小的图像文件的可选路径
  • [--replace]:添加此标志以用缩小版本替换原始图像

测试MCP包装

node test-mcp-wrapper.js [path-to-image] [--replace]

选项:

  • [path-to-image]:要缩小的图像文件的可选路径
  • [--replace]:添加此标志以用缩小版本替换原始图像

📚 例子

看看 examples 显示如何使用MinifyPics服务器的示例代码目录:

# Start the server
npm start

# In another terminal, run the example
node examples/minify-example.js [path-to-image] [output-path] [--replace]

📄 许可证

麻省理工学院

👤 作者

你的名字

🙏 致谢