Wan モデルを使用して、テキスト指示で画像を編集します。複数画像の入出力、画像融合、被写体の特徴維持、オブジェクト検出をサポートします。
はじめに
wan2.7-image-pro を使用して、2 つの入力画像とテキストプロンプトから編集済み画像を生成します。
プロンプト:画像 2 のグラフィティを画像 1 の車にスプレーする
|
入力画像 1 |
入力画像 2 |
出力画像 (wan2.7-image-pro) |
|
|
|
|
呼び出しを行う前に、API キーを取得し、API キーを環境変数としてエクスポートしてください。SDK を使用して呼び出しを行うには、DashScope SDK をインストールしてください。
同期呼び出し
DashScope Python SDK のバージョンが 1.25.15 以降、DashScope Java SDK のバージョンが 2.22.13 以降であることを確認してください。
Python
リクエストの例
import os
import base64
import mimetypes
import urllib.request
import dashscope
from dashscope.aigc.image_generation import ImageGeneration
from dashscope.api_entities.dashscope_response import Message
# 以下はシンガポールリージョンの base_url です。 base_url はリージョンによって異なります。
dashscope.base_http_api_url = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1"
# 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えます: api_key="sk-xxx"
# API キーはリージョンによって異なります。 API キーを取得するには、https://www.alibabacloud.com/help/en/model-studio/get-api-key にアクセスしてください。
api_key = os.getenv("DASHSCOPE_API_KEY")
# --- Base64 エンコード関数 ---
# Base64 エンコード形式は data:{MIME_type};base64,{base64_data} です。
def encode_file(file_path):
mime_type, _ = mimetypes.guess_type(file_path)
if not mime_type or not mime_type.startswith("image/"):
raise ValueError("Unsupported or unrecognized image format")
with open(file_path, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read()).decode("utf-8")
return f"data:{mime_type};base64,{encoded_string}"
"""
画像の入力方法:
以下に 3 つの画像入力方法を示します。 いずれか 1 つを選択する必要があります。
1. パブリック URL を使用する: この方法は、一般公開されている画像に適しています。
2. ローカルファイルを使用する: この方法は、ローカルでの開発とテストに適しています。
3. Base64 エンコーディングを使用する: この方法は、非公開の画像や暗号化された伝送が必要なシナリオに適しています。
"""
# [方法 1] パブリックイメージの URL を使用する
image_1 = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/pjeqdf/car.webp"
image_2 = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/xsunlm/paint.webp"
# [方法 2] ローカルファイルを使用する (絶対パスと相対パスをサポート)
# image_1 = "file:///path/to/your/car.png"
# image_2 = "file:///path/to/your/paint.png"
# [方法 3] Base64 エンコードされた画像を使用する
# image_1 = encode_file("/path/to/your/car.png")
# image_2 = encode_file("/path/to/your/paint.png")
message = Message(
role="user",
content=[
{"text": "Spray the graffiti from image 2 onto the car in image 1"},
{"image": image_1},
{"image": image_2},
],
)
print("----sync call, please wait a moment----")
rsp = ImageGeneration.call(
model="wan2.7-image-pro",
api_key=api_key,
messages=[message],
watermark=False,
n=1,
size="2K", # wan2.7-image-pro は、テキストからの画像生成でのみ 4K 解像度をサポートします。 画像編集と複数画像の生成では、最大 2K の解像度をサポートします。
)
# 結果の画像 URL を抽出し、画像をローカルファイルに保存します。
if rsp.status_code == 200:
for i, choice in enumerate(rsp.output.choices):
for j, content in enumerate(choice["message"]["content"]):
if content.get("type") == "image":
image_url = content["image"]
file_name = f"output_{i}_{j}.png"
# 結果の URL は 24 時間有効です。 速やかにダウンロードしてください。
urllib.request.urlretrieve(image_url, file_name)
print(f"Image saved to {file_name}")
else:
print(f"Failed: status_code={rsp.status_code}, message={rsp.message}")
レスポンスの例
URL は 24 時間有効です。速やかに画像をダウンロードしてください。
{
"status_code": 200,
"request_id": "81d868c6-6ce1-92d8-a90d-d2ee71xxxxxx",
"code": "",
"message": "",
"output": {
"text": null,
"finish_reason": null,
"choices": [
{
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": [
{
"image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
"type": "image"
}
]
}
}
],
"audio": null,
"finished": true
},
"usage": {
"input_tokens": 18790,
"output_tokens": 2,
"characters": 0,
"image_count": 1,
"size": "2985*1405",
"total_tokens": 18792
}
}
Java
リクエストの例
import com.alibaba.dashscope.aigc.imagegeneration.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.Constants;
import com.alibaba.dashscope.utils.JsonUtils;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* wan2.7-image-pro 画像編集 - 同期呼び出しの例
*/
public class Main {
static {
// 以下はシンガポールリージョンの URL です。base_url はリージョンによって異なります。
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えます: apiKey="sk-xxx"
// API キーはリージョンによって異なります。API キーを取得するには、https://www.alibabacloud.com/help/en/model-studio/get-api-key にアクセスしてください
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
// --- Base64 エンコード関数 ---
// Base64 エンコード形式: data:{MIME_type};base64,{base64_data}
public static String encodeFile(String filePath) throws IOException {
byte[] fileContent = Files.readAllBytes(Paths.get(filePath));
String base64String = Base64.getEncoder().encodeToString(fileContent);
String mimeType = Files.probeContentType(Paths.get(filePath));
return "data:" + mimeType + ";base64," + base64String;
}
public static void basicCall() throws ApiException, NoApiKeyException, UploadFileException, IOException {
/*
* 画像の入力方法の説明:
* 以下に 3 つの画像入力方法を示します。いずれか 1 つを選択してください。
* 1. パブリック URL を使用する: 一般公開されている画像に適しています。
* 2. ローカルファイルを使用する: ローカルでの開発とテストに適しています。
* 3. Base64 エンコーディングを使用する: 非公開の画像や暗号化された送信が必要なシナリオに適しています。
*/
// 方法 1: パブリックイメージの URL を使用します。
String image1 = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/pjeqdf/car.webp";
String image2 = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/xsunlm/paint.webp";
// 方法 2: ローカルファイルを使用します。絶対パスと相対パスの両方がサポートされています。
// 形式: file:// + ファイルパス
// String image1 = "file:///path/to/your/car.png";
// String image2 = "file:///path/to/your/paint.png";
// 方法 3: Base64 エンコードされた画像を使用します。
// String image1 = encodeFile("/path/to/your/car.png");
// String image2 = encodeFile("/path/to/your/paint.png");
// 複数画像の入力メッセージを構築します。
ImageGenerationMessage message = ImageGenerationMessage.builder()
.role("user")
.content(Arrays.asList(
// 複数画像の入力がサポートされています。複数のリファレンス画像を提供できます。
Collections.singletonMap("text", "Spray the graffiti from image 2 onto the car in image 1"),
Collections.singletonMap("image", image1),
Collections.singletonMap("image", image2)
)).build();
ImageGenerationParam param = ImageGenerationParam.builder()
.apiKey(apiKey)
.model("wan2.7-image-pro")
.messages(Collections.singletonList(message))
.n(1)
.size("2K") // wan2.7-image-pro の場合、4K 解像度をサポートするのはテキストからの画像生成シナリオのみです。画像編集とコラージュ生成は、最大 2K の解像度をサポートします。
.build();
ImageGeneration imageGeneration = new ImageGeneration();
ImageGenerationResult result = null;
try {
System.out.println("---画像編集の同期呼び出し、しばらくお待ちください----");
result = imageGeneration.call(param);
} catch (ApiException | NoApiKeyException | UploadFileException e) {
throw new RuntimeException(e.getMessage());
}
// 結果の画像 URL を抽出し、ローカルファイルに保存します。
for (int i = 0; i < result.getOutput().getChoices().size(); i++) {
List<Map<String, Object>> contents = result.getOutput().getChoices().get(i)
.getMessage().getContent();
for (int j = 0; j < contents.size(); j++) {
if ("image".equals(contents.get(j).get("type"))) {
String imageUrl = (String) contents.get(j).get("image");
String fileName = "output_" + i + "_" + j + ".png";
// 結果の URL は 24 時間有効です。速やかに画像をダウンロードしてください。
try (InputStream in = new URL(imageUrl).openStream()) {
Files.copy(in, Paths.get(fileName), StandardCopyOption.REPLACE_EXISTING);
}
System.out.println("画像が " + fileName + " に保存されました");
}
}
}
}
public static void main(String[] args) throws ApiException, NoApiKeyException, UploadFileException, IOException {
basicCall();
}
}
レスポンスの例
URL は 24 時間有効です。速やかに保存してください。
{
"requestId": "1bf6173a-e8de-9f75-94d3-5e618f875xxx",
"usage": {
"input_tokens": 18790,
"output_tokens": 2,
"total_tokens": 18792,
"image_count": 1,
"size": "2985*1405"
},
"output": {
"choices": [
{
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": [
{
"image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
"type": "image"
}
]
}
}
],
"finished": true
},
"status_code": 200,
"code": "",
"message": ""
}
curl
リクエストの例
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
"model": "wan2.7-image-pro",
"input": {
"messages": [
{
"role": "user",
"content": [
{"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/pjeqdf/car.webp"},
{"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/xsunlm/paint.webp"},
{"text": "イメージ 2 のグラフィティをイメージ 1 の車にスプレーで描いてください"}
]
}
]
},
"parameters": {
"size": "2K",
"n": 1,
"watermark": false
}
}'
レスポンスの例
{
"output": {
"choices": [
{
"finish_reason": "stop",
"message": {
"content": [
{
"image": "https://dashscope-xxx.oss-xxx.aliyuncs.com/xxx.png?Expires=xxx",
"type": "image"
}
],
"role": "assistant"
}
}
],
"finished": true
},
"usage": {
"image_count": 1,
"input_tokens": 10867,
"output_tokens": 2,
"size": "1488*704",
"total_tokens": 10869
},
"request_id": "71dfc3c6-f796-9972-97e4-bc4efc4faxxx"
}
非同期呼び出し
DashScope Python SDK のバージョンが 1.25.15 以降、DashScope Java SDK のバージョンが 2.22.13 以降であることを確認してください。
Python
リクエストの例
import os
import base64
import mimetypes
import urllib.request
import dashscope
from dashscope.aigc.image_generation import ImageGeneration
from dashscope.api_entities.dashscope_response import Message
from http import HTTPStatus
# 以下はシンガポールリージョンの base_url です。base_url はリージョンによって異なります。
dashscope.base_http_api_url = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1"
# 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えてください: api_key="sk-xxx"
# API キーはリージョンによって異なります。API キーを取得するには、https://www.alibabacloud.com/help/en/model-studio/get-api-key にアクセスしてください
api_key = os.getenv("DASHSCOPE_API_KEY")
# --- Base64 エンコード関数 ---
# Base64 エンコード形式は data:{MIME_type};base64,{base64_data} です
def encode_file(file_path):
mime_type, _ = mimetypes.guess_type(file_path)
if not mime_type or not mime_type.startswith("image/"):
raise ValueError("Unsupported or unrecognized image format.")
with open(file_path, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read()).decode("utf-8")
return f"data:{mime_type};base64,{encoded_string}"
"""
画像入力メソッド:
以下に 3 つの画像入力メソッドを示します。いずれか 1 つを選択してください。
1. パブリック URL を使用する - パブリックにアクセス可能な画像に適しています。
2. ローカルファイルを使用する - ローカルでの開発とテストに適しています。
3. Base64 エンコーディングを使用する - 非公開画像や暗号化された伝送が必要なシナリオに適しています。
"""
# [メソッド 1] パブリックイメージ URL を使用する
image_1 = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/pjeqdf/car.webp"
image_2 = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/xsunlm/paint.webp"
# [メソッド 2] ローカルファイルを使用する (絶対パスと相対パスをサポート)
# image_1 = "file:///path/to/your/car.png"
# image_2 = "file:///path/to/your/paint.png"
# [メソッド 3] Base64 エンコードされた画像を使用する
# image_1 = encode_file("/path/to/your/car.png")
# image_2 = encode_file("/path/to/your/paint.png")
# 非同期タスクを作成します。
def create_async_task():
print("Creating async task...")
message = Message(
role="user",
content=[
{"text": "Spray the graffiti from image 2 onto the car in image 1."},
{"image": image_1},
{"image": image_2},
],
)
response = ImageGeneration.async_call(
model="wan2.7-image-pro",
api_key=api_key,
messages=[message],
watermark=False,
n=1,
size="2K", # wan2.7-image-pro は、テキストからの画像生成シナリオでのみ 4K 解像度をサポートします。画像編集とコラージュ生成は、最大 2K の解像度をサポートします。
)
if response.status_code == 200:
print("Task created successfully:", response)
return response
else:
raise Exception(f"Failed to create task: {response.code} - {response.message}")
# タスクが完了するのを待ちます。
def wait_for_completion(task_response):
print("Waiting for task completion...")
status = ImageGeneration.wait(task=task_response, api_key=api_key)
if status.output.task_status == "SUCCEEDED":
print("Task succeeded!")
# 結果の画像 URL を抽出し、画像をローカルファイルに保存します。
for i, choice in enumerate(status.output.choices):
for j, content in enumerate(choice["message"]["content"]):
if content.get("type") == "image":
image_url = content["image"]
file_name = f"output_{i}_{j}.png"
# 結果の URL は 24 時間有効です。時間内に画像をダウンロードしてください。
urllib.request.urlretrieve(image_url, file_name)
print(f"Image saved to {file_name}")
else:
raise Exception(f"Task failed with status: {status.output.task_status}")
# 非同期タスクに関する情報を取得します。
def fetch_task_status(task):
print("Fetching task status...")
status = ImageGeneration.fetch(task=task, api_key=api_key)
if status.status_code == HTTPStatus.OK:
print("Task status:", status.output.task_status)
print("Response details:", status)
else:
print(f"Failed to fetch status: {status.code} - {status.message}")
# 非同期タスクをキャンセルします。
def cancel_task(task):
print("Canceling task...")
response = ImageGeneration.cancel(task=task, api_key=api_key)
if response.status_code == HTTPStatus.OK:
print("Task canceled successfully:", response.output.task_status)
else:
print(f"Failed to cancel task: {response.code} - {response.message}")
# メインの実行フロー。
if __name__ == "__main__":
task = create_async_task()
wait_for_completion(task)
レスポンスの例
-
タスク作成時のレスポンス例
{ "status_code": 200, "request_id": "4fb3050f-de57-4a24-84ff-e37ee5xxxxxx", "code": "", "message": "", "output": { "text": null, "finish_reason": null, "choices": null, "audio": null, "task_id": "127ec645-118f-4884-955d-0eba8dxxxxxx", "task_status": "PENDING" }, "usage": { "input_tokens": 0, "output_tokens": 0, "characters": 0 } } -
タスク結果クエリのレスポンス例
URL は 24 時間有効です。速やかに画像をダウンロードしてください。
{ "status_code": 200, "request_id": "3b99aae5-d26f-9059-8dd0-ee9ca4804xxx", "code": null, "message": "", "output": { "text": null, "finish_reason": null, "choices": [ { "finish_reason": "stop", "message": { "role": "assistant", "content": [ { "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx", "type": "image" } ] } } ], "audio": null, "task_id": "127ec645-118f-4884-955d-0eba8dxxxxxx", "task_status": "SUCCEEDED", "submit_time": "2026-03-31 22:58:47.646", "scheduled_time": "2026-03-31 22:58:47.683", "end_time": "2026-03-31 22:58:59.642", "finished": true }, "usage": { "input_tokens": 18711, "output_tokens": 2, "characters": 0, "size": "2985*1405", "total_tokens": 18713, "image_count": 1 } }
Java
リクエストの例
import com.alibaba.dashscope.aigc.imagegeneration.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.Constants;
import com.alibaba.dashscope.utils.JsonUtils;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* wan2.7-image-pro 画像編集 - 非同期呼び出しの例
*/
public class Main {
static {
// 次の URL はシンガポールリージョン用です。base_url はリージョンによって異なります。
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えてください: apiKey="sk-xxx"
// API キーはリージョンによって異なります。API キーを取得するには、https://www.alibabacloud.com/help/en/model-studio/get-api-key をご覧ください
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
// --- Base64 エンコード関数 ---
// Base64 エンコード形式は data:{MIME_type};base64,{base64_data} です
public static String encodeFile(String filePath) throws IOException {
byte[] fileContent = Files.readAllBytes(Paths.get(filePath));
String base64String = Base64.getEncoder().encodeToString(fileContent);
String mimeType = Files.probeContentType(Paths.get(filePath));
return "data:" + mimeType + ";base64," + base64String;
}
public static void asyncCall() throws ApiException, NoApiKeyException, UploadFileException, IOException {
/*
* 画像入力方法の説明:
* 以下の 3 つの画像入力方法が提供されています。いずれか 1 つを選択できます。
* 1. パブリック URL を使用 - 一般公開されている画像に適しています。
* 2. ローカルファイルを使用 - ローカルでの開発とテストに適しています。
* 3. Base64 エンコーディングを使用 - 非公開の画像や暗号化された送信が必要なシナリオに適しています。
*/
// [方法 1] パブリックイメージ URL を使用
String image1 = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/pjeqdf/car.webp";
String image2 = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/xsunlm/paint.webp";
// [方法 2] ローカルファイルを使用 (絶対パスと相対パスをサポート)
// 必要なフォーマット: file:// + ファイルパス
// String image1 = "file:///path/to/your/car.png";
// String image2 = "file:///path/to/your/paint.png";
// [方法 3] Base64 エンコードされた画像を使用
// String image1 = encodeFile("/path/to/your/car.png");
// String image2 = encodeFile("/path/to/your/paint.png");
// 複数画像の入力メッセージを構築
ImageGenerationMessage message = ImageGenerationMessage.builder()
.role("user")
.content(Arrays.asList(
// 複数画像の入力をサポートしています。複数のリファレンス画像を提供できます。
Collections.singletonMap("text", "画像 2 の落書きを画像 1 の車にスプレーペイントします"),
Collections.singletonMap("image", image1),
Collections.singletonMap("image", image2)
)).build();
ImageGenerationParam param = ImageGenerationParam.builder()
.apiKey(apiKey)
.model("wan2.7-image-pro")
.n(1)
.size("2K") // wan2.7-image-pro モデルは、テキストからの画像生成の場合にのみ 4K 解像度をサポートします。画像編集および合成画像生成の場合、サポートされる最大解像度は 2K です。
.messages(Arrays.asList(message))
.build();
ImageGeneration imageGeneration = new ImageGeneration();
ImageGenerationResult result = null;
try {
System.out.println("---画像編集の非同期呼び出し、タスクの作成----");
result = imageGeneration.asyncCall(param);
} catch (ApiException | NoApiKeyException | UploadFileException e) {
throw new RuntimeException(e.getMessage());
}
System.out.println("タスク作成結果:");
System.out.println(JsonUtils.toJson(result));
String taskId = result.getOutput().getTaskId();
// タスクが完了するのを待ちます
waitTask(taskId);
}
public static void waitTask(String taskId) throws ApiException, NoApiKeyException, IOException {
ImageGeneration imageGeneration = new ImageGeneration();
System.out.println("\n---タスクの完了を待機しています----");
ImageGenerationResult result = imageGeneration.wait(taskId, apiKey);
// 結果の画像 URL を取得し、ローカルファイルに保存します
for (int i = 0; i < result.getOutput().getChoices().size(); i++) {
List<Map<String, Object>> contents = result.getOutput().getChoices().get(i)
.getMessage().getContent();
for (int j = 0; j < contents.size(); j++) {
if ("image".equals(contents.get(j).get("type"))) {
String imageUrl = (String) contents.get(j).get("image");
String fileName = "output_" + i + "_" + j + ".png";
// 結果の URL は 24 時間有効です。時間内に画像をダウンロードしてください。
try (InputStream in = new URL(imageUrl).openStream()) {
Files.copy(in, Paths.get(fileName), StandardCopyOption.REPLACE_EXISTING);
}
System.out.println("画像が " + fileName + " に保存されました");
}
}
}
}
public static void main(String[] args) throws ApiException, NoApiKeyException, UploadFileException, IOException {
asyncCall();
}
}
レスポンスの例
-
タスク作成時のレスポンス例
{ "requestId": "ccf4b2f4-bf30-9e13-9461-3a28c6a7bxxx", "output": { "task_id": "8811b4a4-00ac-4aa2-a2fd-017d3b90cxxx", "task_status": "PENDING" }, "status_code": 200, "code": "", "message": "" } -
タスク結果クエリのレスポンス例
URL は 24 時間有効です。速やかに保存してください。
{ "requestId": "60a08540-f1c1-9e76-8cd3-d5949db8cxxx", "usage": { "input_tokens": 18711, "output_tokens": 2, "total_tokens": 18713, "image_count": 1, "size": "2985*1405" }, "output": { "choices": [ { "finish_reason": "stop", "message": { "role": "assistant", "content": [ { "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx", "type": "image" } ] } } ], "task_id": "8811b4a4-00ac-4aa2-a2fd-017d3b90cxxx", "task_status": "SUCCEEDED", "finished": true, "submit_time": "2026-03-31 19:57:58.840", "scheduled_time": "2026-03-31 19:57:58.877", "end_time": "2026-03-31 19:58:11.563" }, "status_code": 200, "code": "", "message": "" }
curl
ステップ 1:タスクを作成してタスク ID を取得
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/image-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "X-DashScope-Async: enable" \
--data '{
"model": "wan2.7-image-pro",
"input": {
"messages": [
{
"role": "user",
"content": [
{"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/pjeqdf/car.webp"},
{"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/xsunlm/paint.webp"},
{"text": "イメージ 2 のグラフィティをイメージ 1 の車にスプレーで描画してください"}
]
}
]
},
"parameters": {
"size": "2K",
"n": 1,
"watermark": false
}
}'
レスポンスの例
{
"output": {
"task_status": "PENDING",
"task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx"
},
"request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx"
}
ステップ 2:タスク ID で結果をクエリ
前のステップで取得した task_id を使用して、task_status が SUCCEEDED または FAILED になるまで API を介してタスクステータスをポーリングします。
{task_id} を、前の API 呼び出しで返された task_id の値に置き換えます。task_id は 24 時間クエリに有効です。
curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"レスポンスの例
画像 URL は 24 時間有効です。速やかに画像をダウンロードしてください。
{
"request_id": "810fa5f5-334c-91f3-aaa4-ed89cf0caxxx",
"output": {
"task_id": "a81ee7cb-014c-473d-b842-76e98311cxxx",
"task_status": "SUCCEEDED",
"submit_time": "2026-03-26 17:16:01.663",
"scheduled_time": "2026-03-26 17:16:01.716",
"end_time": "2026-03-26 17:16:22.961",
"finished": true,
"choices": [
{
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": [
{
"image": "https://dashscope-xxx.oss-xxx.aliyuncs.com/xxx.png?Expires=xxx",
"type": "image"
}
]
}
}
]
},
"usage": {
"size": "2976*1408",
"total_tokens": 11017,
"image_count": 1,
"output_tokens": 2,
"input_tokens": 11015
}
}
wan2.5-i2i-preview は、異なる API エンドポイントとパラメーターを使用します。
モデルの選択
-
wan2.7-image-pro および wan2.7-image (推奨):正確な編集や複数の整合性のある画像の生成に最適です。
-
正確なローカル編集:特定の領域を選択して要素を移動、置換、または追加します。e コマースのレタッチやデザイン調整に最適です。
-
マルチパネル生成:1 回の呼び出しで複数の整合性のあるスタイルの画像を生成します。コミックの絵コンテや製品シリーズに最適です。
-
-
wan2.6-image:テキスト/画像の混合または複数の参照を使用した様式化された編集。画像内にテキストを生成し、最大 4 つの参照画像を受け入れます。
-
wan2.5-i2i-preview:単純な画像編集と複数画像の融合に適しています。
デモギャラリー
イメージからイメージのセット
|
入力画像 |
出力画像 |
|
|
|
|
|
|
インタラクティブ編集
|
入力画像 |
出力画像 |
|
|
画像 1 に基づいて編集します。ボックス 1 で選択されたラズベリーをレモンに、ボックス 2 のラズベリーをイチゴに、ボックス 3 のラズベリーをブルーベリーに置き換えます。結果は元の画像と調和するように統合し、参照ボックスと番号は含めず、残りのコンテンツは変更しないでください。 |
|
|
画像 1 で選択されたパターンを画像 2 の選択された領域に配置します。 |
複数画像融合
|
入力画像 |
出力画像 |
|
|
画像 1 の少年と画像 2 の犬のポートレートを撮影します。少年は犬を抱きしめており、どちらもとても幸せそうです。スタジオのソフトな照明、青いテクスチャの背景。 |
|
|
画像 1 のドレスを画像 2 の鳥の色を使って再配色します。芸術的にしますが、ドレスのスタイルとモデルは変更しないでください。 |
主体の特徴の保持
|
入力画像 |
出力画像 |
|
|
人物の顔の特徴と髪型は変更しないでください。人物はオフホワイトのキャミソールを着ています。透明な水槽が画面全体を埋め尽くし、金魚が泳ぎ、水中に泡があります。人物の顔は透明な水槽と水を通して見えます。右下から薄暗い黄色の光が人物の顔に当たっています。泳ぐ魚がランダムに人物を覆い、光と影の相互作用を生み出します。 |
|
|
「季節の変わり目」をテーマにしたポラロイド写真 4 枚セットを生成してください。各写真は公園の木の下の同じ場所で撮影されていますが、それぞれ春、夏、秋、冬の風景を示しています。人物の服装も季節に合わせてください:春は薄手のジャケット、夏は半袖シャツ、秋はトレンチコート、冬はマフラーと厚手のコート。この写真セットを食卓の上に置いてください。 |
検出とセグメンテーション
|
入力画像 |
出力画像 |
|
|
画像内のノートパソコンと目覚まし時計を検出し、バウンディングボックスを描画し、「laptop」と「clock」とラベル付けします。 |
|
|
画像内のガラスのコップをセグメント化します。 |
要素の抽出
|
入力画像 |
出力画像 |
|
|
アップロードされた写真から衣料品を抽出し、真っ白な背景に平置きで配置します。リアルなディテールと素材の質感を維持します。ファッション e コマーススタイルで、衣料品のディスプレイに適しています。 |
|
|
主要な人物を切り抜き、真っ白な背景に配置します。 |
テキスト編集
|
入力画像 |
出力画像 |
|
|
画像からすべてのウォーターマークを削除します。 |
|
|
砂の上に手で「Time for Holiday?」とさりげなく書きます。 |
|
|
18 を 29 に、JUNE を SEPTEMBER に変更します。 |
カメラと視点の編集
|
入力画像 |
出力画像 |
|
|
人物の特徴を変えずに、正面、側面、背面のビューを生成します。 |
|
|
この写真を魚眼レンズで再撮影します。 |
入力仕様
入力画像の仕様
|
仕様 |
wan2.7-image-pro, wan2.7-image |
wan2.6-image |
wan2.5-i2i-preview |
|
入力画像数 |
0 から 9 (0 はテキストからの画像生成モードに対応) |
画像編集:1 から 4 / テキストと画像の混合:0 から 1 |
1 から 3 |
|
画像形式 |
JPEG, JPG, PNG (アルファチャンネルはサポートされていません), BMP, WEBP |
JPEG, JPG, PNG (アルファチャンネルはサポートされていません), BMP, WEBP |
JPEG, JPG, PNG (アルファチャンネルはサポートされていません), BMP, WEBP |
|
画像の幅と高さの範囲 |
[240, 8000] ピクセル |
[240, 8000] ピクセル |
[384, 5000] ピクセル |
|
ファイルサイズ |
≤ 20 MB |
≤ 10 MB |
≤ 10 MB |
|
アスペクト比 |
[1:8, 8:1] |
無制限 |
[1:4, 4:1] |
画像の入力順序
プロンプト内の画像番号は配列の位置に対応します:最初の画像は「画像 1」、2 番目の画像は「画像 2」です。「[image 1]」や「[image 2]」のようなマーカーも使用できます。
{
"content": [
{"text": "編集指示、例:画像 1 の目覚まし時計を画像 2 の食卓の花瓶の隣に置く"},
{"image": "https://example.com/image1.png"},
{"image": "https://example.com/image2.png"}
]
}
|
入力画像 |
出力画像 |
||
|
画像 1 |
画像 2 |
プロンプト:画像 1 を画像 2 の上に移動 |
プロンプト:画像 2 を画像 1 の上に移動 |
画像の入力方法
次のいずれかの方法で画像を渡します:
主な機能
1. 指示追従 (プロンプト)
パラメーター:messages.content.text または input.prompt (必須)、negative_prompt (任意)。
-
text または prompt (ポジティブプロンプト):出力画像のコンテンツ、被写体、シーン、スタイル、照明、構図を記述します。
-
negative_prompt (ネガティブプロンプト):「ぼやけている」や「余分な指」など、不要なコンテンツを指定します。
|
パラメーター |
wan2.7-image-pro, wan2.7-image |
wan2.6-image |
wan2.5-i2i-preview |
|
text |
必須、最大 5,000 文字 |
必須、最大 2,000 文字 |
サポートされていません |
|
prompt |
サポートされていません |
サポートされていません |
必須、最大 2,000 文字 |
|
negative_prompt |
サポートされていません |
サポート、最大 500 文字 |
サポート、最大 500 文字 |
2. インテリジェントなプロンプトリライトを有効にする
パラメーター:parameters.prompt_extend (bool, デフォルトは true)。
短いプロンプトを拡張して画質を向上させますが、応答時間が長くなります。
ベストプラクティス:
-
有効にする:プロンプトが簡潔または広範な場合。
-
無効にする:細かいディテールの制御、詳細な説明、または遅延に敏感なシナリオの場合。
prompt_extendをfalseに設定します。
|
パラメーター |
wan2.7-image-pro, wan2.7-image |
wan2.6-image |
wan2.5-i2i-preview |
|
prompt_extend |
サポートされていません |
サポート (画像編集モードのみ) |
サポート |
3. 出力画像の解像度を設定する
パラメーター:parameters.size (string)、形式は "width*height"。
|
パラメーター |
wan2.7-image-pro, wan2.7-image |
wan2.6-image |
wan2.5-i2i-preview |
|
size |
方法 1:出力画像の解像度を指定する (推奨) 編集モード (少なくとも 1 つの画像が渡された場合) では、オプションの出力解像度ティアは
方法 2:生成される画像の幅と高さのピクセル値を指定する
テキストからの画像生成シナリオの wan2.7-image-pro のみ 4K 解像度をサポートします。 |
方法 1:入力画像のアスペクト比を参照する (推奨) 編集モード (
方法 2:生成される画像の幅と高さのピクセル値を指定する
実際の出力画像のピクセル値は、指定された値に最も近い 16 の倍数になります。 |
生成される画像の幅と高さのピクセル値の指定のみをサポート
|
4. インタラクティブな精密編集
parameters.bbox_list を使用して、編集する特定の領域を選択します。wan2.7-image-pro および wan2.7-image のみでサポートされています。
-
リストの長さ:入力画像の数と一致する必要があります。編集が不要な画像には空のリスト
[]を使用します。 -
座標形式:
[x1, y1, x2, y2](左上の x、左上の y、右下の x、右下の y)。座標は、左上を原点 (0, 0) とし、x 軸を右、y 軸を下とする絶対ピクセル値です。 -
数量制限:画像ごとに最大 2 つのバウンディングボックス。
例:イメージ 1 には 2 つのバウンディングボックスがあり、イメージ 2 にはバウンディングボックスがない、3 つの入力イメージ
[
[[0, 0, 12, 12], [25, 25, 100, 100]], # 画像 1 (2 ボックス)
[], # 画像 2 (ボックスなし)
[[10, 10, 50, 50]] # 画像 3 (1 ボックス)
]
課金とレート制限
API リファレンス
各モデルは異なるエンドポイントとリクエスト構造を使用します:
|
モデル |
エンドポイント (シンガポールリージョンの例) |
|
|
同期 API: 非同期 API:
|
|
|
非同期 API:
|
-
wan2.7/wan2.6:messagesフォーマットを使用します。messages[].content配列で、imageパラメーターにイメージを、textパラメーターにプロンプトを渡します。 -
wan2.5:input.images配列で画像を、input.promptパラメーターでプロンプトを渡します。
|
wan2.7-image-pro, wan2.7-image, wan2.6-image |
wan2.5-i2i-preview |
|
|
入出力パラメーターについては、Wan2.7 - 画像生成と編集、Wan2.6 - 画像生成と編集、Wanxiang – 一般画像編集 2.5 をご参照ください。








































