mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
Renames 18 ambiguous or hard-to-search tool names so image tools self-qualify like the other modalities ("Compress" becomes "Compress Image"), and cleans up a few awkward names. Propagated across search (constants.ts), display (en.ts + 20 locales), the OpenAPI base spec + 20 locale specs, and the docs tool-page headings in 21 languages. Removes the duplicate "Normalize Audio" summary shared by the video and audio endpoints. Tool ids and routes are unchanged, so no API paths or bookmarks break.
2.6 KiB
2.6 KiB
description, i18n_source_hash, i18n_provenance, i18n_output_hash
| description | i18n_source_hash | i18n_provenance | i18n_output_hash |
|---|---|---|---|
| 按像素、百分比或使用适配模式调整图片尺寸。 | 53866e8266b8 | human | 0a8f45ef34da |
调整图片尺寸
通过指定精确的像素尺寸、百分比缩放系数,或控制图片如何适配目标尺寸的适配模式来调整图片尺寸。
API 端点
POST /api/v1/tools/image/resize
接受包含一个图片文件和一个 JSON settings 字段的 multipart 表单数据。
参数
| 参数 | 类型 | 是否必填 | 默认值 | 说明 |
|---|---|---|---|---|
| width | integer | 否 | - | 目标宽度(像素,最大 16383) |
| height | integer | 否 | - | 目标高度(像素,最大 16383) |
| fit | string | 否 | "contain" |
图片如何适配尺寸:contain、cover、fill、inside、outside |
| withoutEnlargement | boolean | 否 | false |
若图片小于目标尺寸则阻止放大 |
| percentage | number | 否 | - | 按百分比缩放(例如 50 表示缩至一半) |
必须至少提供 width、height 或 percentage 之一。
适配模式
- contain - 调整尺寸以适配于给定尺寸之内,保持宽高比(可能留有空白)
- cover - 调整尺寸以覆盖给定尺寸,保持宽高比(可能裁剪)
- fill - 拉伸以精确匹配尺寸(忽略宽高比)
- inside - 类似
contain,但只缩小,绝不放大 - outside - 类似
cover,但只缩小,绝不放大
请求示例
curl -X POST http://localhost:1349/api/v1/tools/image/resize \
-H "Authorization: Bearer si_your-api-key" \
-F "file=@photo.jpg" \
-F 'settings={"width": 800, "height": 600, "fit": "contain"}'
按百分比调整尺寸:
curl -X POST http://localhost:1349/api/v1/tools/image/resize \
-H "Authorization: Bearer si_your-api-key" \
-F "file=@photo.jpg" \
-F 'settings={"percentage": 50}'
响应示例
{
"jobId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"downloadUrl": "/api/v1/download/a1b2c3d4-e5f6-7890-abcd-ef1234567890/photo.jpg",
"originalSize": 2450000,
"processedSize": 980000
}
说明
- 任一轴向的最大尺寸为 16383 像素(Sharp/libvips 限制)。
- 输出格式与输入格式一致。HEIC、RAW、PSD 和 SVG 输入会在处理前自动解码。
- 调整尺寸前会自动应用 EXIF 方向。
withoutEnlargement标志对于批处理很有用,因为其中某些图片可能已经小于目标尺寸。