# 图片水印裁剪缩略接口:5 分钟生成第一张缩略图
> 接口/接入点:图片水印裁剪缩略接口(apiCode=1)· 1-1 生成缩略图 · 是否免费:免费(有档位限制) · 请求方式:POST/GET · 返回格式:JSON · 适用人群:新注册用户、初级开发者 · 阅读时间:5 分钟
## 核心要点
- 注册易源账号、在控制台拿到 AppKey,即可免费调用图片处理接口。
- 用 1-1 接入点、传 `type=rate&rate=0.6`,按 60% 比例生成缩略图。
- 返回体里的 `des_pic_url` 就是生成后的图片地址,复制即可预览。
## Why:为什么需要它
做网站或 App 时,原图往往几 MB,直接展示既慢又费流量。把原图按比例缩成缩略图,预览更快、存储更省。本接口注册即免费,不用买资源包,先用起来再说。
## What:前置条件与接口速览
| 项 | 值 |
|------|------|
| 接口地址 | `https://route.showapi.com/1-1?appKey=YOUR_APPKEY` |
| 接入点 | 1-1 生成缩略图 |
| 必填参数 | `type`(size/rate)、`src_img`(File,multipart 上传) |
| 可选参数 | `height`、`width`、`keepRate`(type=size 有效)、`rate`(type=rate 有效,0~1) |
| 鉴权 | AppKey(query 参数 `appKey`) |
| 计费 | 免费(有使用档次限制,具体以官方档位说明为准) |
| 集成能力 | MCP、OpenAPI 3.0 |
## How:三步跑通
1. 注册并登录 https://www.showapi.com ,进入控制台「我的应用」创建应用,拿到 AppKey。
2. 准备一张本地图片(如 `demo.jpg`)。
3. 调用 1-1,把 AppKey 替换成你的真实值。
**Python(requests)**
```python
import requests
url = "https://route.showapi.com/1-1"
params = {"appKey": "YOUR_APPKEY"}
data = {
"type": "rate",
"rate": "0.6", # 缩到原图的 60%
}
files = {"src_img": open("demo.jpg", "rb")}
try:
r = requests.post(url, params=params, data=data, files=files, timeout=10)
r.raise_for_status()
body = r.json()["showapi_res_body"]
if body.get("ret_code") != "0" and str(body.get("ret_code")) != "0":
print("处理失败 ret_code=", body.get("ret_code"))
else:
print("缩略图地址:", body["des_pic_url"])
except Exception as e:
print("请求异常:", e)
```
**cURL**
```bash
curl -X POST "https://route.showapi.com/1-1?appKey=YOUR_APPKEY" \
-F "type=rate" \
-F "rate=0.6" \
-F "src_img=@demo.jpg"
```
**Node.js(fetch)**
```javascript
import fs from "fs";
const url = "https://route.showapi.com/1-1?appKey=YOUR_APPKEY";
const form = new FormData();
form.append("type", "rate");
form.append("rate", "0.6");
form.append("src_img", new Blob([fs.readFileSync("demo.jpg")]), "demo.jpg");
try {
const res = await fetch(url, { method: "POST", body: form });
const json = await res.json();
const body = json.showapi_res_body;
if (String(body.ret_code) !== "0") { console.log("失败", body.ret_code); }
else { console.log("缩略图地址:", body.des_pic_url); }
} catch (e) { console.log("请求异常:", e); }
```
## 返回示例与解析
```json
{
"showapi_res_code": 0,
"showapi_res_error": "",
"showapi_res_id": "ce135f6739294c63be0c021b76b6fbff",
"showapi_res_body": {
"ret_code": "0",
"des_pic_url": "http://app1.showapi.com/temp/1.jpg"
}
}
```
- `showapi_res_body` 是业务数据包裹层,图片地址在 `des_pic_url`。
- `ret_code` 为 `"0"` 表示成功,其他值表示失败。字段完整说明见[返回字段全解](https://www.showapi.com/guides/image-process-response-codes-1)。
## 进阶/边界
- `type=size` 时按 `width`/`height` 固定尺寸缩略,`keepRate=1` 保持原比例;`type=rate` 时按 `rate`(0~1)比例缩。
- 免费接口有档位/频率限制,批量调用请看[频率控制篇](https://www.showapi.com/guides/image-process-ratelimit-1)。
## FAQ
**Q1:提示 ret_code 非 0?** 先看 `showapi_res_error` 文案;多为参数缺失或图片超限。确认 `src_img` 已作为文件上传。
**Q2:AppKey 在哪?** 控制台「我的应用」里创建应用后获取,替换示例中的 `YOUR_APPKEY`。
**Q3:支持 URL 传图吗?** 1-1 只收文件;要用网络图片走 1-8 接入点,见[URL 缩略篇](https://www.showapi.com/guides/url-thumbnail-guide-1)。
**Q4:生成的图能保存多久?** 以 `des_pic_url` 返回地址的有效期为准,生产环境建议自行下载归档。
## 相关能力 / 下一步阅读
- [图片水印裁剪缩略接口返回字段全解:ret_code 与 des_pic_url 一文读懂](https://www.showapi.com/guides/image-process-response-codes-1)
- [图片水印裁剪缩略接口实战:网站/App 图库如何接入缩略图生成](https://www.showapi.com/guides/thumbnail-library-integration-1)
- **本系列共 13 篇**:查看[图片水印裁剪缩略接口指南总目录](https://www.showapi.com/guides/image-process-guides-1)