feat(compress): improve quality guardrails and format conversion

This commit is contained in:
2026-02-08 00:12:27 +08:00
parent f8955d8a6c
commit 65387ca846
8 changed files with 233 additions and 102 deletions

View File

@@ -274,9 +274,10 @@ Idempotency-Key: <key> # 建议
| `file` | File | 是 | 图片文件 |
| `compression_rate` | Integer | 否 | 压缩率 1-100压缩后体积占原图比例数值越小压缩越强100 表示不压缩),优先级高于 `level` |
| `level` | String | 否 | `high` / `medium` / `low`(兼容参数,默认 `medium` |
| `output_format` | String | 否 | 已停用,仅支持保持原格式 |
| `output_format` | String | 否 | 输出格式:`png/jpeg/webp/avif/gif/bmp/tiff/ico`(默认保持原格式 |
| `max_width` | Integer | 否 | 最大宽度(等比缩放) |
| `max_height` | Integer | 否 | 最大高度(等比缩放) |
| `target_size_bytes` | Integer | 否 | 目标体积(字节),仅 `jpeg/webp/avif` 输出支持;会优先保清晰度并在必要时小幅缩放 |
| `preserve_metadata` | Boolean | 否 | 是否保留元数据(默认 `false` |
响应:
@@ -309,6 +310,8 @@ X-API-Key: <your-api-key> # 或 Bearer token不建议匿名
Idempotency-Key: <key> #
```
表单字段与 `/compress` 一致(包括 `output_format``target_size_bytes`)。
成功响应:
- HTTP `200`
- Body压缩后的图片二进制
@@ -339,7 +342,7 @@ Idempotency-Key: <key> # 建议
| `files[]` | File[] | 是 | 图片文件数组(上限由套餐决定) |
| `compression_rate` | Integer | 否 | 压缩率 1-100压缩后体积占原图比例数值越小压缩越强100 表示不压缩),优先级高于 `level` |
| `level` | String | 否 | `high` / `medium` / `low`(兼容参数) |
| `output_format` | String | 否 | 已停用,仅支持保持原格式 |
| `output_format` | String | 否 | 输出格式:`png/jpeg/webp/avif/gif/bmp/tiff/ico`(默认保持原格式 |
| `preserve_metadata` | Boolean | 否 | 是否保留元数据(默认 `false` |
响应: