ImageGlider.Cli
1.9.7
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet tool install --global ImageGlider.Cli --version 1.9.7
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
dotnet tool install --local ImageGlider.Cli --version 1.9.7
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=ImageGlider.Cli&version=1.9.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
nuke :add-package ImageGlider.Cli --version 1.9.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ImageGlider
ImageGlider 是一个功能强大的跨平台图像处理工具套件,使用 C# (.NET 9) 和 ImageSharp 实现。项目采用模块化架构设计,包含核心类库、命令行工具、Web API、示例程序和完整的单元测试,支持 AOT 编译以获得原生性能。
通过ImageGlider,您可以轻松进行图像处理操作,完全摆脱外部依赖,无需 ImageMagick、Node.js 或 Python,适合在 .NET 项目中内嵌、分发或集成自动化流程中使用。
🚀 跨平台、零依赖、高性能、全功能的图像处理解决方案!
📁 项目架构
- ImageGlider - 核心类库,提供完整的图像处理功能
- ImageGlider.Cli - 命令行工具,支持16种命令和批量处理
- ImageGlider.WebApi - RESTful API服务,提供HTTP接口
- ImageGlider.Example - 示例程序,展示核心类库的典型用法
- ImageGlider.Tests - 完整的单元测试套件,180个测试用例,69.4%覆盖率
✨ 功能特点
🎯 核心图像处理功能
- 🖼️ 格式转换:支持 JPEG、PNG、GIF、BMP、TIFF、WebP 等多种图像格式的相互转换
- 📏 尺寸调整:支持拉伸、保持宽高比、裁剪等多种调整模式
- 🗜️ 压缩优化:智能压缩算法,在保持质量的同时减小文件体积
- ✂️ 图像裁剪:精确裁剪指定区域,支持中心裁剪和自定义坐标裁剪
- 🖼️ 缩略图生成:快速生成高质量缩略图,支持多种尺寸模式
- 💧 水印功能:支持文本和图片水印,9种位置选择,可调透明度和缩放
- 🧹 元数据清理:一键清除 EXIF、ICC、XMP 等隐私敏感的元数据信息
- 🎨 颜色调整:调整亮度、对比度、饱和度、色相、伽马值等颜色参数
- ℹ️ 信息提取:获取图像详细信息,支持JSON格式输出
🛠️ 技术特性
- 🚀 跨平台:基于 .NET 9 和 ImageSharp,支持 Windows、Linux、macOS
- ⚡ AOT 编译:支持原生AOT编译,启动速度快,内存占用低
- 📦 零依赖:无需安装额外的图像处理工具或运行时环境
- 🧩 模块化设计:核心功能封装为独立类库,便于集成和扩展
- 🔧 多种接口:提供CLI工具、Web API、核心类库三种使用方式
💻 使用方式
- 命令行工具:16种专业命令,支持单文件和批量处理
- Web API:RESTful接口,支持HTTP文件上传和处理
- 核心类库:直接集成到.NET项目中使用
- 批量处理:自动扫描目录,支持递归处理和文件过滤
- 详细日志:完整的日志记录,支持多种日志级别
- 错误处理:完善的异常处理机制,提供详细的处理结果信息
前置条件
- .NET 9 SDK
- 支持的图像格式:JPEG、PNG、GIF、BMP、TIFF、WebP 等(由 ImageSharp 提供支持)
依赖项
- SixLabors.ImageSharp (3.1.8) - 跨平台图像处理库
- xUnit - 单元测试框架(仅测试项目)
📦 安装方式
方式一:作为 .NET Global Tool 安装(推荐)
dotnet tool install --global ImageGlider.Cli
方式二:从源码构建
git clone https://github.com/Deali-Axy/image-glider.git
cd image-glider
dotnet build -c Release
方式三:发布为单文件可执行程序
# Windows x64
dotnet publish src/ImageGlider.Cli -c Release -r win-x64 --self-contained -p:PublishSingleFile=true
# Linux x64
dotnet publish src/ImageGlider.Cli -c Release -r linux-x64 --self-contained -p:PublishSingleFile=true
# macOS x64 (Intel)
dotnet publish src/ImageGlider.Cli -c Release -r osx-x64 --self-contained -p:PublishSingleFile=true
# macOS ARM64 (Apple Silicon)
dotnet publish src/ImageGlider.Cli -c Release -r osx-arm64 --self-contained -p:PublishSingleFile=true
方式四:AOT 编译(性能最佳)
# Windows x64 AOT
dotnet publish src/ImageGlider.Cli -c Release -r win-x64 -p:PublishAot=true
# Linux x64 AOT
dotnet publish src/ImageGlider.Cli -c Release -r linux-x64 -p:PublishAot=true
# macOS x64 AOT
dotnet publish src/ImageGlider.Cli -c Release -r osx-x64 -p:PublishAot=true
# macOS ARM64 AOT
dotnet publish src/ImageGlider.Cli -c Release -r osx-arm64 -p:PublishAot=true
🚀 快速开始
🖥️ 命令行工具使用
安装完成后,您可以直接使用 imageglider
命令:
# 查看所有可用命令
imageglider --help
# 查看特定命令的帮助
imageglider help convert
🌐 Web API 服务
启动Web API服务:
cd src/ImageGlider.WebApi
dotnet run
# 服务将在 http://localhost:5000 启动
📚 核心类库集成
在您的.NET项目中引用核心类库:
<PackageReference Include="ImageGlider" Version="1.0.0" />
using ImageGlider;
// 转换图像格式
ImageConverter.ConvertImage("input.png", "output.jpg", 85);
// 调整图像尺寸
ImageConverter.ResizeImage("input.jpg", "output.jpg", 800, 600);
🧪 运行测试
# 运行所有测试
dotnet test
# 运行测试并生成覆盖率报告
dotnet test --collect:"XPlat Code Coverage"
🎯 运行示例程序
# 运行示例程序,了解核心类库的用法
dotnet run --project src/ImageGlider.Example
📖 使用说明
🖥️ 命令行工具完整指南
ImageGlider CLI 提供了16种专业命令,支持单文件和批量处理。所有命令都经过精心设计,提供丰富的参数选项。
📋 可用命令列表
命令 | 描述 | 批量版本 |
---|---|---|
convert |
格式转换 | batch-convert |
resize |
尺寸调整 | batch-resize |
compress |
图像压缩 | batch-compress |
crop |
图像裁剪 | batch-crop |
thumbnail |
缩略图生成 | batch-thumbnail |
watermark |
添加水印 | batch-watermark |
strip-metadata |
清理元数据 | batch-strip-metadata |
adjust |
颜色调整 | batch-adjust |
info |
信息提取 | batch-info |
🆘 查看帮助信息
# 查看所有命令
imageglider --help
# 查看特定命令的详细帮助
imageglider help convert
imageglider help batch-resize
🔄 格式转换 (convert)
# 单文件转换
imageglider convert -s image.jpg -t image.png -q 85
# 批量转换目录下所有JPEG文件为PNG
imageglider batch-convert -sd ./input -od ./output -se .jpg -te .png -q 90
# 转换特定格式并设置质量
imageglider convert -s photo.webp -t photo.jpg --quality 95
📏 尺寸调整 (resize)
# 按指定宽度和高度调整(拉伸模式)
imageglider resize -s input.jpg -t output.jpg -w 800 -h 600
# 保持宽高比调整(只指定宽度)
imageglider resize -s input.jpg -t output.jpg -w 800 --mode keep-aspect
# 批量调整目录下所有图片
imageglider batch-resize -sd ./photos -od ./resized -w 1920 -h 1080 -ext .jpg
#### 🗜️ 压缩优化 (compress)
```bash
# 默认压缩(质量75)
imageglider compress -s input.jpg -t compressed.jpg
# 指定压缩质量(1-100)
imageglider compress -s input.jpg -t output.jpg -q 60
# 批量压缩目录下所有JPEG文件
imageglider batch-compress -sd ./photos -od ./compressed -ext .jpg -q 80
✂️ 图像裁剪 (crop)
# 从指定坐标裁剪
imageglider crop -s input.png -t cropped.png -x 100 -y 50 -w 400 -h 300
# 中心裁剪
imageglider crop -s input.jpg -t cropped.jpg -w 800 -h 600 --center
# 批量裁剪
imageglider batch-crop -sd ./photos -od ./cropped -w 500 -h 500 --center -ext .jpg
🖼️ 生成缩略图 (thumbnail)
# 生成标准缩略图
imageglider thumbnail -s input.jpg -t thumb.jpg -w 150 -h 150
# 保持宽高比的缩略图
imageglider thumbnail -s input.jpg -t thumb.jpg -w 200 --keep-aspect
# 批量生成缩略图
imageglider batch-thumbnail -sd ./photos -od ./thumbs -w 300 -h 300 -ext .jpg
💧 添加水印 (watermark)
# 添加文本水印
imageglider watermark -s input.jpg -t watermarked.jpg --text "© 2024" --position bottom-right
# 添加图片水印
imageglider watermark -s input.jpg -t watermarked.jpg --image logo.png --opacity 50 --scale 0.3
# 批量添加水印
imageglider batch-watermark -sd ./photos -od ./watermarked --text "Sample" -ext .jpg
🧹 元数据清理 (strip-metadata)
# 清理所有元数据
imageglider strip-metadata -s input.jpg -t clean.jpg --all
# 只清理EXIF数据
imageglider strip-metadata -s input.jpg -t clean.jpg --exif
# 批量清理元数据
imageglider batch-strip-metadata -sd ./photos -od ./cleaned -ext .jpg --all
🎨 颜色调整 (adjust)
# 调整亮度和对比度
imageglider adjust -s input.jpg -t adjusted.jpg --brightness 20 --contrast 15
# 调整饱和度和色相
imageglider adjust -s input.jpg -t adjusted.jpg --saturation 30 --hue 45
# 批量颜色调整
imageglider batch-adjust -sd ./photos -od ./adjusted --brightness 10 --gamma 1.2 -ext .jpg
ℹ️ 信息提取 (info)
# 显示图像基本信息
imageglider info -s image.jpg
# 以JSON格式输出详细信息
imageglider info -s image.jpg --json
# 批量提取信息并保存到文件
imageglider batch-info -sd ./photos --json --output info.json
### 🌐 Web API 使用指南
ImageGlider 提供了完整的RESTful API服务,支持通过HTTP接口进行图像处理。
#### 启动API服务
```bash
cd src/ImageGlider.WebApi
dotnet run
# 服务将在 http://localhost:5000 启动
API 端点示例
# 上传并转换图像格式
curl -X POST "http://localhost:5000/api/convert" \
-F "file=@input.jpg" \
-F "targetFormat=png" \
-F "quality=85"
# 上传并调整图像尺寸
curl -X POST "http://localhost:5000/api/resize" \
-F "file=@input.jpg" \
-F "width=800" \
-F "height=600" \
-F "mode=KeepAspectRatio"
# 上传并压缩图像
curl -X POST "http://localhost:5000/api/compress" \
-F "file=@input.jpg" \
-F "quality=70"
# 获取图像信息
curl -X POST "http://localhost:5000/api/info" \
-F "file=@input.jpg"
📚 核心类库集成
在您的.NET项目中直接使用ImageGlider核心功能:
using ImageGlider;
using ImageGlider.Enums;
// 格式转换
bool success = ImageConverter.ConvertImage("input.jpg", "output.png", quality: 85);
// 尺寸调整
bool resized = ImageConverter.ResizeImage("input.jpg", "output.jpg", 800, 600, ResizeMode.KeepAspectRatio);
// 图像压缩
bool compressed = ImageConverter.CompressImage("input.jpg", "compressed.jpg", quality: 70);
// 添加文本水印
bool watermarked = ImageConverter.AddTextWatermark("input.jpg", "watermarked.jpg", "© 2024", WatermarkPosition.BottomRight);
// 批量处理
var result = ImageConverter.BatchConvert("./input", "./output", ".jpg", ".png", quality: 90);
Console.WriteLine($"成功转换: {result.SuccessfulConversions}/{result.TotalFiles}");
// 获取图像信息
var info = ImageConverter.GetImageInfo("image.jpg");
Console.WriteLine($"尺寸: {info.Width}x{info.Height}, 格式: {info.Format}");
高级功能示例
using ImageGlider.Processors;
using ImageGlider.Core;
// 使用处理器工厂
var resizer = ImageProcessorFactory.CreateResizer();
var compressor = ImageProcessorFactory.CreateCompressor();
var watermark = ImageProcessorFactory.CreateWatermark();
// 链式处理
bool processed = resizer.ProcessImage("input.jpg", "temp.jpg", 800, 600) &&
compressor.ProcessImage("temp.jpg", "final.jpg", 80);
📊 测试覆盖率
当前测试状态:
- 测试用例数量: 180个
- 行覆盖率: 69.4%
- 分支覆盖率: 57.3%
- 测试通过率: 100%
运行测试并生成覆盖率报告:
# 运行所有测试
dotnet test
# 生成覆盖率报告
dotnet test --collect:"XPlat Code Coverage" --results-directory ./TestResults
# 生成HTML覆盖率报告
reportgenerator -reports:"TestResults/**/coverage.cobertura.xml" -targetdir:"TestResults/CoverageReport" -reporttypes:Html
🏗️ 项目架构
📁 目录结构
ImageGlider/
├── src/
│ ├── ImageGlider/ # 核心类库
│ │ ├── Core/ # 核心接口和工厂
│ │ ├── Processors/ # 图像处理器
│ │ ├── Utilities/ # 工具类
│ │ ├── Enums/ # 枚举定义
│ │ └── ImageConverter.cs # 主要API入口
│ ├── ImageGlider.Cli/ # 命令行工具
│ │ ├── Commands/ # 16种命令实现
│ │ └── Program.cs # CLI程序入口
│ ├── ImageGlider.WebApi/ # Web API服务
│ │ ├── Endpoints/ # API端点
│ │ ├── Services/ # 服务层
│ │ └── Program.cs # API程序入口
│ └── ImageGlider.Example/ # 示例程序
│ └── Program.cs # 使用示例
└── tests/
└── ImageGlider.Tests/ # 单元测试
├── TestHelpers/ # 测试辅助工具
└── *.cs # 180个测试用例
🔧 核心组件
- ImageConverter: 主要API入口,提供所有图像处理功能
- ImageProcessorFactory: 处理器工厂,创建各种专用处理器
- ImageSizeCalculator: 尺寸计算工具,支持多种调整模式
- 处理器系列: 格式转换、尺寸调整、压缩、裁剪、水印等专用处理器
🛠️ 开发指南
环境要求
- .NET 9 SDK
- Visual Studio 2022 或 JetBrains Rider(推荐)
- Git
构建和测试
# 克隆项目
git clone https://github.com/Deali-Axy/image-glider.git
cd image-glider
# 恢复依赖
dotnet restore
# 构建项目
dotnet build -c Release
# 运行测试
dotnet test
# 运行示例
dotnet run --project src/ImageGlider.Example
AOT 发布优化
# Windows x64 AOT(优化体积)
dotnet publish src/ImageGlider.Cli -c Release -r win-x64 -p:PublishAot=true -p:IlcOptimizationPreference=Size
# Linux x64 AOT(优化性能)
dotnet publish src/ImageGlider.Cli -c Release -r linux-x64 -p:PublishAot=true -p:IlcOptimizationPreference=Speed
支持的平台
- Windows: win-x64, win-arm64
- macOS: osx-x64, osx-arm64 (Intel & Apple Silicon)
- Linux: linux-x64, linux-arm64
🤝 贡献指南
我们欢迎各种形式的贡献!
如何贡献
- Fork 本仓库
- 创建您的特性分支 (
git checkout -b feature/AmazingFeature
) - 提交您的更改 (
git commit -m 'Add some AmazingFeature'
) - 推送到分支 (
git push origin feature/AmazingFeature
) - 打开一个 Pull Request
贡献类型
- 🐛 Bug 修复: 发现并修复问题
- ✨ 新功能: 添加新的图像处理功能
- 📚 文档: 改进文档和示例
- 🧪 测试: 增加测试覆盖率
- 🎨 代码质量: 重构和优化代码
- 🌐 国际化: 添加多语言支持
开发规范
- 遵循 C# 编码规范
- 为新功能添加单元测试
- 更新相关文档
- 确保所有测试通过
📄 许可证
本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。
🙏 致谢
- SixLabors.ImageSharp - 强大的跨平台图像处理库
- .NET 团队 - 提供优秀的开发平台
- 所有贡献者和用户的支持
📞 联系方式
- 项目主页: GitHub Repository
- 问题反馈: GitHub Issues
- 功能请求: GitHub Discussions
⭐ 如果这个项目对您有帮助,请给我们一个星标!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
Version | Downloads | Last Updated |
---|---|---|
1.9.8 | 197 | 8/8/2025 |
1.9.7 | 202 | 8/6/2025 |
1.9.5 | 210 | 8/6/2025 |
1.9.1 | 155 | 8/4/2025 |
1.9.0 | 152 | 8/4/2025 |
1.8.0 | 160 | 8/4/2025 |
1.7.0 | 153 | 8/4/2025 |
1.6.0 | 156 | 8/4/2025 |
1.5.0 | 155 | 8/4/2025 |
1.4.0 | 154 | 8/4/2025 |
1.3.3 | 151 | 8/4/2025 |
1.3.2 | 148 | 8/4/2025 |
1.3.1 | 154 | 8/4/2025 |
1.3.0 | 154 | 8/4/2025 |
1.2.0 | 147 | 8/4/2025 |
1.1.3 | 109 | 8/3/2025 |
1.1.2 | 109 | 8/3/2025 |