| Crates.io | img-squeeze |
| lib.rs | img-squeeze |
| version | 0.1.1 |
| created_at | 2025-09-09 08:45:05.119635+00 |
| updated_at | 2025-09-12 03:14:10.939005+00 |
| description | A fast and efficient image compression tool with Walrus storage support |
| homepage | https://github.com/luojiyin1987/img-squeeze |
| repository | https://github.com/luojiyin1987/img-squeeze |
| max_upload_size | |
| id | 1830432 |
| size | 188,094 |
一个用 Rust 编写的快速、高效的图片压缩工具,支持多线程并行处理、批量压缩、多种图片格式和去中心化存储。
# 克隆仓库
git clone https://github.com/yourusername/img-squeeze.git
cd img-squeeze
# 构建项目
cargo build --release
# 将二进制文件添加到 PATH
sudo cp target/release/img-squeeze /usr/local/bin/
cargo install img-squeeze
# 基本压缩(自动线程数)
img-squeeze compress input.jpg output.jpg
# 查看帮助
img-squeeze --help
img-squeeze compress --help
img-squeeze batch --help
# 指定线程数压缩
img-squeeze compress input.jpg output.jpg -j 4 # 使用 4 个线程
img-squeeze compress input.jpg output.jpg -j 8 # 使用 8 个线程
# 自动线程数(默认,根据CPU核心数)
img-squeeze compress input.jpg output.jpg
# 指定压缩质量 (1-100, 默认 80)
img-squeeze compress input.jpg output.jpg -q 90
# 调整图片尺寸
img-squeeze compress input.jpg output.jpg -w 800 # 设置宽度为 800px
img-squeeze compress input.jpg output.jpg -H 600 # 设置高度为 600px
img-squeeze compress input.jpg output.jpg -w 800 -H 600 # 同时设置宽度和高度
# 指定输出格式
img-squeeze compress input.png output.jpg -f jpeg
img-squeeze compress input.jpg output.webp -f webp
# 多线程 + 高级选项组合
img-squeeze compress input.jpg output.jpg -j 6 -q 85 -w 1200 -H 800 -f webp
# 批量压缩整个目录
img-squeeze batch ./images ./compressed
# 批量压缩(递归处理子目录)
img-squeeze batch ./photos ./output -r
# 批量压缩 + 线程控制
img-squeeze batch ./images ./compressed -j 8
# 批量压缩 + 质量和尺寸调整
img-squeeze batch ./images ./compressed -q 85 -w 1200 -H 800
# 批量压缩 + 格式转换
img-squeeze batch ./images ./webp_output -f webp
# 使用通配符批量处理
img-squeeze batch "*.jpg" ./compressed
img-squeeze batch "./photos/*.png" ./compressed
警告:目前为了节约费用,验证功能。默认上传到 Walrus 的测试网。不能保证文件的存储安全。上传成功后,返回的文件名是随机的字符串,同时不包含文件扩展名。需要用户重命名,加上对应的扩展名。用户体验不好。 有空对 Walrus 提交对应 pr。
# 上传到 Walrus(默认设置)
img-squeeze upload image.jpg
# 上传到自定义 Walrus 节点
img-squeeze upload image.jpg -a https://aggregator.walrus-testnet.walrus.space -p https://publisher.walrus-testnet.walrus.space
# 上传并设置存储时长(epochs)
img-squeeze upload image.jpg -e 20 # 存储20个epoch,约20天
# 临时上传(1 epoch,约24小时后自动删除)
img-squeeze upload image.jpg -t
# 组合选项
img-squeeze upload image.jpg -a https://aggregator.walrus-testnet.walrus.space -e 15
临时文件管理:
-t 标志上传临时文件,24小时后自动删除上传成功后,您将获得:
输出示例:
📤 Uploading to Walrus: "image.jpg"
🔗 Aggregator URL: https://aggregator.walrus-testnet.walrus.space
🔗 Publisher URL: https://publisher.walrus-testnet.walrus.space
⏰ Epochs: Some(10)
✅ Upload successful!
🆔 Blob ID: 3xAm...V7n9
🌐 Access URL: https://aggregator.walrus-testnet.walrus.space/v1/blobs/3xAm...V7n9
📊 File size: 1024 bytes
💡 You can use the blob ID to retrieve the file later
临时上传示例:
📤 Uploading to Walrus: "temp_image.jpg"
🔗 Aggregator URL: https://aggregator.walrus-testnet.walrus.space
🔗 Publisher URL: https://publisher.walrus-testnet.walrus.space
⏰ Epochs: Some(1)
✅ Upload successful!
🆔 Blob ID: MZwz...oSE
🌐 Access URL: https://aggregator.walrus-testnet.walrus.space/v1/blobs/MZwz...oSE
⏰ Temporary file: Will expire after 1 epoch (~24 hours)
🔄 Use without -t flag for longer storage
📊 File size: 406 bytes
💡 You can use the blob ID to retrieve the file later
# 查看图片详细信息
img-squeeze info image.jpg
输出示例:
📋 Getting info for: "image.jpg"
📸 Image Information:
📏 Dimensions: 1920x1080
🎨 Color type: Rgb8
💾 Format: Jpeg
📊 File size: 2,456,789 bytes
📈 Megapixels: 2.1
批量处理完成后会显示详细的性能统计:
📊 Batch Compression Summary:
📁 Total files processed: 150
📊 Total original size: 456,789,123 bytes
📊 Total compressed size: 234,567,890 bytes
🎯 Overall compression ratio: 48.6%
⏱️ Total time: 45.2s
⚡ Average speed: 3.32 files/second
压缩图片文件。
参数:
INPUT - 输入图片文件路径OUTPUT - 输出图片文件路径选项:
-q, --quality <QUALITY> - 压缩质量 (1-100),默认 80-w, --width <WIDTH> - 最大宽度(像素)-H, --height <HEIGHT> - 最大高度(像素)-f, --format <FORMAT> - 输出格式 (jpeg, png, webp)上传图片到 Walrus 去中心化存储网络。
参数:
INPUT - 要上传的图片文件路径选项:
-a, --aggregator-url <AGGREGATOR_URL> - Walrus aggregator URL-p, --publisher-url <PUBLISHER_URL> - Walrus publisher URL-e, --epochs <EPOCHS> - 存储时长(epochs)显示图片的详细信息。
参数:
INPUT - 要分析的图片文件路径# 开发构建
cargo build
# 发布构建
cargo build --release
# 运行测试
cargo test
# 检查代码
cargo check
cargo clippy
本项目集成了简化的 Claude 工作流系统,用于自动化代码质量检查和构建流程:
# 运行完整的 Claude 工作流
./claude-workflow.sh
# 或手动执行各个阶段
cargo check # 检查编译错误
cargo clippy # 代码质量检查
cargo fmt --check # 代码格式检查
cargo test --lib # 运行单元测试
cargo build --release # 构建优化版本
工作流包含:
img-squeeze/
├── src/
│ ├── main.rs # 主程序入口
│ ├── cli.rs # 命令行接口
│ ├── processing.rs # 核心压缩逻辑
│ ├── batch.rs # 批量处理
│ ├── info.rs # 图片信息分析
│ ├── walrus.rs # Walrus 存储集成
│ └── error.rs # 错误处理
├── Cargo.toml # 项目配置
├── LICENSE # MIT 许可证
├── README.md # 项目说明
├── CLAUDE.md # Claude Code 开发指南
├── .claude-workflow.yml # Claude 工作流配置
├── claude-workflow.sh # Claude 工作流执行脚本
└── WALRUS_URLS.md # Walrus 网络地址说明
image 库欢迎贡献代码!请遵循以下步骤:
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)本项目采用 MIT 许可证 - 详见 LICENSE 文件。
如果您遇到问题或有建议,请:
注意:这是一个开源项目,欢迎任何形式的贡献和反馈!