Files
imageproxy/README.md
2025-06-11 11:07:12 +08:00

101 lines
2.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ImageProxy
ImageProxy 是一个高性能的图片代理服务,它能够自动下载、调整大小并优化图片,同时支持 WebP 格式转换。这个服务特别适合用于优化网站图片加载性能。
## 功能特点
- 支持 HTTP/HTTPS 图片源
- 自动调整图片大小
- 转换为 WebP 格式以减小文件大小
- 支持自定义最大尺寸
- 详细的性能指标输出
- 内置 CORS 支持
- 长期缓存支持
## 技术栈
- Rust
- Axum (Web 框架)
- Tokio (异步运行时)
- image-rs (图片处理)
- libwebp (WebP 转换)
## 快速开始
### 使用 Docker
```bash
docker run -p 2999:2999 your-imageproxy-image
```
### 从源码构建
1. 确保已安装 Rust 工具链
2. 克隆仓库
3. 构建项目:
```bash
cargo build --release
```
4. 运行服务:
```bash
./target/release/imageproxy
```
## 使用方法
### 基本用法
```
http://your-server:2999/https://example.com/image.jpg
```
### 调整最大尺寸
```
http://your-server:2999/max_size/500/https://example.com/image.jpg
```
## 响应头信息
服务会在响应中包含以下有用的头信息:
- `Content-Type`: 始终为 `image/webp`
- `Cache-Control`: 设置为长期缓存
- `X-Original-Content-Type`: 原始图片的 Content-Type
- `X-Original-Size`: 原始图片大小(字节)
- `X-Original-Width`: 原始图片宽度
- `X-Original-Height`: 原始图片高度
- `X-Output-Max-Size`: 输出图片的最大尺寸
- `X-Converted-Size`: 转换后的图片大小
- `X-Download-Time`: 下载耗时(毫秒)
- `X-Resize-Time`: 调整大小耗时(毫秒)
- `X-Convert-Time`: 转换耗时(毫秒)
## 限制
- 最大支持下载 10MB 的图片
- 仅支持图片格式的输入
- 输出格式固定为 WebP
## 环境变量
- `LISTEN`: 监听地址和端口默认0.0.0.0:2999
- `RUST_LOG`: 日志级别默认info
## 性能优化
- 使用 WebP 格式进行高效压缩
- 支持异步处理
- 内置缓存控制
- 优化的图片处理算法
## 许可证
[待定]
## 贡献
欢迎提交 Issue 和 Pull Request