Wan 2.7 图片编辑 API:一句话把自拍扔进任何场景

0 阅读2分钟

最近刷到好多人用 AI 把自己的照片 P 到各种场景里——竹林、赛博朋克街头、吉卜力动画。大部分教程都是教你用 ChatGPT 或者 Gemini 的网页版手动操作,但我想要的是 API 调用,能写脚本批量跑的那种。

试了一下阿里的 Wan 2.7 Image Edit,发现它干这个事特别顺手。传一张照片 + 一句话描述你想要的效果,出来的图人物保持得很好,背景融合也自然。关键是 $0.03 一次,随便玩。

准备

pip install wavespeed

Key 去 wavespeed.ai/settings/api-keys 拿。

把人扔进不同场景

先看一下原图,就是这张:

portrait_article3.jpg

核心就一个接口,传图 + 写 prompt:

from wavespeed import Client

client = Client(api_key="wsk_xxxxxxxx")

photo_url = client.upload("./my_photo.jpg")

# 扔进日本竹林
output = client.run(
    "alibaba/wan-2.7/image-edit",
    {
        "images": [photo_url],
        "prompt": "Place the person in a misty Japanese bamboo forest at dawn, soft diffused light filtering through the bamboo, keep the person's face, clothing, and pose exactly unchanged"
    }
)

print(output["outputs"][0])

端点 alibaba/wan-2.7/image-edit,$0.03 一次。

prompt 的关键是后半句一定要写保留条件。不写 "keep the person's face and pose unchanged" 的话,模型有时候会把人也改了,出来一个竹林里的陌生人。

换个场景就是换句 prompt 的事:

# 赛博朋克街头
output = client.run("alibaba/wan-2.7/image-edit", {
    "images": [photo_url],
    "prompt": "Place the person on a rainy cyberpunk street at night, neon signs in Japanese, wet reflections on the ground, cinematic lighting, keep the person unchanged",
    "seed": 42
})

# 吉卜力风格
output = client.run("alibaba/wan-2.7/image-edit", {
    "images": [photo_url],
    "prompt": "Transform the entire image into Studio Ghibli anime style, soft watercolor palette, dreamy clouds in background, keep the person's pose and composition unchanged",
    "seed": 42
})

# 老照片效果
output = client.run("alibaba/wan-2.7/image-edit", {
    "images": [photo_url],
    "prompt": "Transform into a vintage 1970s film photograph, warm faded colors, slight grain, retro color grading, keep the person unchanged",
    "seed": 42
})

固定 seed 的好处是,同一张照片跑不同场景,人物的姿态和表情保持一致,只有背景和风格在变。做成一组发社交媒体效果很好。

four_scenes.jpg

多图参考:把 A 的风格套到 B 上

Wan 2.7 支持传最多 9 张图。第一张是要编辑的目标,后面的是参考。比如你有一张定好调性的品牌图,想把其他照片都调成同样的风格:

style_ref = client.upload("./brand_style.jpg")
target = client.upload("./raw_photo.jpg")

output = client.run("alibaba/wan-2.7/image-edit", {
    "images": [target, style_ref],
    "prompt": "Apply the color palette and lighting style from the second image to the first image, keep the composition of the first image unchanged"
})

prompt 里用 "first image""second image" 指代。这个功能做品牌视觉统一的时候特别好用。

踩坑

prompt 写中文效果不如英文,这个我试了好几次。"把背景换成海边"有时候会把人也改了,但英文版 "Replace the background with a beach, keep the person unchanged" 就很稳。

编辑范围溢出是常见问题。解决办法是约束写得越具体越好:"keep the face unchanged, keep the clothing unchanged, keep the pose unchanged",一个一个列。

别在一次 prompt 里塞太多指令。又换背景又改风格又加特效,效果会打折。拆成两三次跑,每次只改一个东西,$0.03 一次也不心疼。

还有个 Pro 版(alibaba/wan-2.7/image-edit-pro),$0.075 一次,细节更好。我的做法是调 prompt 的时候用普通版,确定效果了再用 Pro 出最终版。

和手动 P 图比

精细修图还是 PS 强。但这个的优势是快、不需要技能、能批量跑。写个循环把同一张照片扔进 20 个场景,几分钟就出来了,手动 P 得搞一整天。

适合"量大、要好玩、不需要像素级精确"的场景。


模型文档:wavespeed.ai/models/alib…
SDK:github.com/WaveSpeedAI…