ImgTools 0.0.1
dotnet tool install --global ImgTools --version 0.0.1
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
dotnet tool install --local ImgTools --version 0.0.1
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=ImgTools&version=0.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
nuke :add-package ImgTools --version 0.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ImgTools - 图片处理命令行工具
一个功能强大的图片处理命令行工具,支持格式转换、压缩、缩放、裁剪、水印等功能。
安装
dotnet tool install --global ImgTools
或者从源码构建:
dotnet build
dotnet publish -c Release
使用方法
基本语法
imgtools [command] [options]
可用命令
1. 格式转换 (convert)
将图片转换为指定格式
# 单个文件转换
imgtools convert -i input.jpg -o output.png
# 批量转换
imgtools convert -i *.jpg -f png -o ./output/
# 转换为WebP格式
imgtools convert -i image.jpg -f webp
# 创建GIF动画
imgtools convert -i frame*.png -f gif -o animation.gif --gifwidth 800 --gifheight 600 --gifdelay 500
# 创建多页TIFF
imgtools convert -i page*.jpg -f tiff -o document.tiff
2. 图片压缩 (compress)
压缩图片文件大小
# 压缩单张图片
imgtools compress -i photo.jpg -q 80
# 批量压缩
imgtools compress -i *.jpg -q 70 -o ./compressed/
# 指定输出格式压缩
imgtools compress -i image.png -q 85 -f webp
# PNG压缩(质量1-9)
imgtools compress -i image.png -q 6 -f png
3. 缩放图片 (resize)
调整图片尺寸
# 按百分比缩放
imgtools resize -i input.jpg -p 50
# 指定宽度,高度按比例
imgtools resize -i image.png -w 1200
# 指定高度,宽度按比例
imgtools resize -i picture.jpg -h 800
4. 裁剪图片 (crop)
裁剪图片指定区域
# 按宽高比裁剪
imgtools crop -i input.jpg -a 16:9
# 居中裁剪正方形
imgtools crop -i photo.jpg -a 1:1
# 批量裁剪
imgtools crop -i *.jpg -a 4:3 -o ./cropped/
5. 添加水印 (watermarker)
为图片添加文字水印
# 添加文字水印
imgtools watermarker -i image.jpg -m "Copyright 2024" --position BottomRight
# 自定义水印样式
imgtools watermarker -i photo.jpg -m "Sample Watermark" --fontcolor "#FFFFFF" --fontsize 36 --opacity 0.5 --position Center
# 批量添加水印
imgtools watermarker -i *.jpg -m "Confidential" --position TopLeft -o ./watermarked/
6. 分割图片 (split)
将图片分割为多个部分
# 网格分割(2x2)
imgtools split -i large_image.jpg --row 2 --col 2
# 自定义行列分割
imgtools split -i grid_image.png --row 3 --col 4
# 批量分割
imgtools split -i *.jpg --row 2 --col 2 -o ./split/
高级用法
组合使用示例
# 先压缩再转换格式
imgtools compress -i raw_image.jpg -q 75 | imgtools convert -f webp
# 批量处理:缩放并添加水印
for file in *.jpg; do
imgtools resize -i "$file" -w 1200 -o ./resized/
imgtools watermarker -i "./resized/$(basename "$file")" -m "Processed" --position BottomRight
done
支持格式
- 输入格式: JPG, PNG, WebP, BMP, GIF, TIFF
- 输出格式: JPG, PNG, WebP, BMP, GIF, TIFF
选项说明
通用选项
-i, --input: 输入文件路径(支持通配符)-o, --output: 输出文件路径或目录-f, --format: 输出格式(jpg, png, webp, bmp, gif, tiff)-m, --marker: 水印文字内容--position: 水印位置(TopLeft, TopRight, BottomLeft, BottomRight, Center)--fontsize: 文字水印字体大小--fontcolor: 文字水印字体颜色--opacity: 水印透明度(0.0-1.0)
质量选项
-q, --quality: 压缩质量(JPG/WebP: 1-99, PNG: 1-9)-p, --percent: 缩放百分比(1-100)
尺寸选项
-w, --width: 目标宽度-h, --height: 目标高度-a, --aspect: 宽高比例(如 16:9, 4:3, 1:1)--row: 分割行数--col: 分割列数
开发
# 克隆项目
git clone <repository-url>
# 构建项目
dotnet build
# 运行测试
dotnet test
# 发布工具
dotnet publish -c Release
许可证
MIT License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. 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 |
|---|---|---|
| 0.0.1 | 123 | 8/23/2025 |