扩图
Last updated: Nov 4, 2026
POST
向四周扩展图片画面。
说明
新图整体面积不得超过原图 3 倍。按目标面积倍数和宽高比计算四个方向比例:
import mathdef calculate_expansion_ratios(width, height, area_multiplier, aspect_ratio): target_area = area_multiplier * width * height target_height = math.sqrt(target_area / aspect_ratio) target_width = target_height * aspect_ratio top = bottom = (target_height - height) / 2 / height left = right = (target_width - width) / 2 / width return f"{top:.4f},{bottom:.4f},{left:.4f},{right:.4f}"# 原图 100x100,扩到 3 倍面积,16:9 -> 0.1495,0.1495,0.6547,0.6547print(calculate_expansion_ratios(100, 100, 3, 16 / 9))使用 TE 北京地域 API Key 鉴权。模型能力、调用约定见 Kling 接口概览。
BearerAuthheader
AuthorizationBearer <token>TE 北京地域 API Key,填写后自动添加 Bearer 前缀。
application/json- body
image*string原图,URL 或 Base64(不带 data: 前缀);jpg/jpeg/png,≤ 10MB,宽高 ≥ 300px,宽高比 1:2.5~2.5:1
up_expansion_ratio*number向上扩充,原图高度的倍数,[0,2]
down_expansion_ratio*number向下扩充,原图高度的倍数,[0,2]
left_expansion_ratio*number向左扩充,原图宽度的倍数,[0,2]
right_expansion_ratio*number向右扩充,原图宽度的倍数,[0,2]
prompt?string≤ 2500 字符
n?integer[1,9],默认 1
watermark_info?{"enabled": true} 同时生成含水印结果;不支持自定义水印
成功;具体状态及结果见响应字段。
application/json- response
taskId?string任务 ID
requestId?string请求 ID,用于排查
code?string错误码,异常时返回
message?string错误信息,异常时返回
curl -X POST 'https://vod.bj.baidubce.com/v3/aigc/kl/images/editing/expand' \ -H 'Content-Type: application/json' \ -d '{ "prompt": "人物站立,近景特写", "image": "https://example.com/origin.png", "up_expansion_ratio": 0.1, "down_expansion_ratio": 0.1, "left_expansion_ratio": 0.1, "right_expansion_ratio": 0.1, "n": 1, "watermark_info": { "enabled": true }}'Example Response200
{ "taskId": "tsk-xxxxxxxxxxxxxxxx", "requestId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}
