Skip to main content
Image editing

Image editing - Wan2.7/2.6/2.5

Edit images using text instructions with Wan2.7, 2.6, and 2.5 models.

The Wanxiang image editing model series supports multi-image input and output. You can use text instructions to perform tasks such as image editing, multi-image fusion, subject feature preservation, and object detection and segmentation.

Getting started

This example shows how to use the wan2.7-image-pro model to generate an edited image based on two input images and a prompt. Prompt: Spray the graffiti from image 2 onto the car in image 1
Input image 1Input image 2Output image (wan2.7-image-pro)
car
paint
output
  • Synchronous call
  • Asynchronous call
Important Ensure that your DashScope Python SDK is version 1.25.15 or later, and your DashScope Java SDK is version 2.22.13 or later.
import os
import dashscope
from dashscope.aigc.image_generation import ImageGeneration
from dashscope.api_entities.dashscope_response import Message

dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

# If you have not set an environment variable, replace the next line with: api_key="sk-xxx"
api_key = os.getenv("DASHSCOPE_API_KEY")

message = Message(
    role="user",
    # Supports local files, such as "image": "file://car.png"
    content=[
        {
            "text": "Apply the graffiti from image 2 onto the car in image 1"
        },
        {
            "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"
        }
    ]
)
print("----Synchronous 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"
    )

print(rsp)
The wan2.5-i2i-preview model uses different API endpoints and parameter formats.

Synchronous call (wan2.5)

Important Make sure your DashScope Python SDK version is at least 1.25.2 and your DashScope Java SDK version is at least 2.22.2.
import base64
import mimetypes
from http import HTTPStatus
from urllib.parse import urlparse, unquote
from pathlib import PurePosixPath

import dashscope
import requests
from dashscope import ImageSynthesis
import os

dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

# If you have not configured an environment variable, replace the next line with: api_key="sk-xxx"
api_key = os.getenv("DASHSCOPE_API_KEY")

# --- Input image: Base64 encoding ---
# Base64 format: 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}"

"""
Image input methods:
Choose one of the following:

1. Public URL — best for publicly accessible images
2. Local file — best for local development and testing
3. Base64 encoding — best for private images or secure transmission
"""

# [Method 1] Public image URL
image_url_1 = "https://img.alicdn.com/imgextra/i3/O1CN0157XGE51l6iL9441yX_!!6000000004770-49-tps-1104-1472.webp"
image_url_2 = "https://img.alicdn.com/imgextra/i3/O1CN01SfG4J41UYn9WNt4X1_!!6000000002530-49-tps-1696-960.webp"

# [Method 2] Local file (supports absolute and relative paths)
# Format: file:// + file path
# Example (absolute path):
# image_url_1 = "file://" + "/path/to/your/image_1.png"     # Linux/macOS
# image_url_2 = "file://" + "C:/path/to/your/image_2.png"  # Windows
# Example (relative path):
# image_url_1 = "file://" + "./image_1.png"                 # Adjust to your path
# image_url_2 = "file://" + "./image_2.png"                # Adjust to your path

# [Method 3] Base64-encoded image
# image_url_1 = encode_file("./image_1.png")               # Adjust to your path
# image_url_2 = encode_file("./image_2.png")              # Adjust to your path

print('----sync call, please wait a moment----')
rsp = ImageSynthesis.call(api_key=api_key,
                          model="wan2.5-i2i-preview",
                          prompt="Place the alarm clock from image 1 beside the vase on the dining table in image 2.",
                          images=[image_url_1, image_url_2],
                          negative_prompt="",
                          n=1,
                          # size="1280*1280",
                          prompt_extend=True,
                          watermark=False,
                          seed=12345)
print('response: %s' % rsp)
if rsp.status_code == HTTPStatus.OK:
    # Save images to current directory
    for result in rsp.output.results:
        file_name = PurePosixPath(unquote(urlparse(result.url).path)).parts[-1]
        with open('./%s' % file_name, 'wb+') as f:
            f.write(requests.get(result.url).content)
else:
    print('sync_call Failed, status_code: %s, code: %s, message: %s' %
          (rsp.status_code, rsp.code, rsp.message))

Asynchronous call (wan2.5)

Important Make sure your DashScope Python SDK version is at least 1.25.2 and your DashScope Java SDK version is at least 2.22.2.
import os
from http import HTTPStatus
from urllib.parse import urlparse, unquote
from pathlib import PurePosixPath
import dashscope
import requests
from dashscope import ImageSynthesis

dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

# If you have not configured an environment variable, replace the next line with: api_key="sk-xxx"
api_key = os.getenv("DASHSCOPE_API_KEY")

# Public image URLs
image_url_1 = "https://img.alicdn.com/imgextra/i3/O1CN0157XGE51l6iL9441yX_!!6000000004770-49-tps-1104-1472.webp"
image_url_2 = "https://img.alicdn.com/imgextra/i3/O1CN01SfG4J41UYn9WNt4X1_!!6000000002530-49-tps-1696-960.webp"

def async_call():
    print('----create task----')
    task_info = create_async_task()
    print('----wait task----')
    wait_async_task(task_info)

# Create an asynchronous task
def create_async_task():
    rsp = ImageSynthesis.async_call(api_key=api_key,
                                    model="wan2.5-i2i-preview",
                                    prompt="Place the alarm clock from image 1 beside the vase on the dining table in image 2.",
                                    images=[image_url_1, image_url_2],
                                    negative_prompt="",
                                    n=1,
                                    # size="1280*1280",
                                    prompt_extend=True,
                                    watermark=False,
                                    seed=12345)
    print(rsp)
    if rsp.status_code == HTTPStatus.OK:
        print(rsp.output)
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (rsp.status_code, rsp.code, rsp.message))
    return rsp

# Wait for the asynchronous task to finish
def wait_async_task(task):
    rsp = ImageSynthesis.wait(task=task, api_key=api_key)
    print(rsp)
    if rsp.status_code == HTTPStatus.OK:
        print(rsp.output)
        # Save file to current directory
        for result in rsp.output.results:
            file_name = PurePosixPath(unquote(urlparse(result.url).path)).parts[-1]
            with open('./%s' % file_name, 'wb+') as f:
                f.write(requests.get(result.url).content)
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (rsp.status_code, rsp.code, rsp.message))

# Fetch asynchronous task status
def fetch_task_status(task):
    status = ImageSynthesis.fetch(task=task, api_key=api_key)
    print(status)
    if status.status_code == HTTPStatus.OK:
        print(status.output.task_status)
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (status.status_code, status.code, status.message))

# Cancel an asynchronous task. Only PENDING tasks can be canceled.
def cancel_task(task):
    rsp = ImageSynthesis.cancel(task=task, api_key=api_key)
    print(rsp)
    if rsp.status_code == HTTPStatus.OK:
        print(rsp.output.task_status)
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (rsp.status_code, rsp.code, rsp.message))

if __name__ == '__main__':
    async_call()

Model Selection

  • wan2.7-image-pro, wan2.7-image (Recommended): This model is suitable for scenarios that require high editing precision or the generation of multiple content-consistent images.
    • Precise Local Editing: You can select a specific area in the image. Then, you can move, replace, or add new elements to objects in that area. This feature is suitable for e-commerce image retouching and design draft adjustments.
    • Multi-frame Continuous Image Generation: You can output multiple images with consistent styles at once. This feature is suitable for comic panels, product series images, and sequential story images.
  • wan2.6-image: This model is suitable for stylized editing scenarios that involve mixed text and images or multiple reference images. It supports generating corresponding text content when creating images and accepts up to 4 reference images as input.
  • wan2.5-i2i-preview: This model is suitable for simple image editing and multi-image blending.
For input and output specifications of each model, see Input Image Specifications and Output Image Resolution.

Demonstration

Generate Image Groups

Input ImageOutput Image
Wan_图片生成_一位 20 岁的东亚男性,头发是卷卷的半长发,文艺气质,五官立体,眉眼清秀,穿着简约白色 T 恤或浅蓝色衬衫,少年感,自然气质。-2026-03-31-19-26-24
output
wan_image_reqid_57d7a71c-1932-4de8-8c32-be0f3fd5696f_n1-2026-03-31-19-32-44
output

Interactive Editing

Input ImageOutput Image
Interactive editing input
Interactive editing output
5eecdaf48460cde5f7fd58249809b192a118accde85283f275b8339e1c4c24831b75b38faadcd24bec177c308ebd5304463ca8e345548eb5f551b6ba01cd2c8d2d9b5606fa569ff7ba4077816ac9b801464f65aedbcf494f4fb4c8ed7016461c-combine
5eecdaf48460cde5f7fd58249809b192a118accde85283f275b8339e1c4c24831b75b38faadcd24bec177c308ebd530460436714d0283cee289325430893028097a53a8e5d630fb1c2d4c85d8cbb68a4387575c4b03700344fb4c8ed7016461c-2026-03-31-19-13-38

Multi-Image Fusion

Input ImageOutput Image
5eecdaf48460cde5544f9fac410016bc2fe4c1b4d23666c075b8339e1c4c24831b75b38faadcd24bec177c308ebd5304e9d05d028a65a9ac270ee730e44b8c75c6634a9b9a7a70240d438b02b2f2153dc68966b442378d1d4fb4c8ed7016461c-combine
5eecdaf48460cde5544f9fac410016bc2fe4c1b4d23666c075b8339e1c4c24831b75b38faadcd24bec177c308ebd53044b9a1d72dee2f8507ee704b9cef3832907ff1182f52507c9bc4737520762d46a722e658f57cda6524fb4c8ed7016461c-2025-12-29-19-11-31
5eecdaf48460cde5544f9fac410016bc2fe4c1b4d23666c075b8339e1c4c24831b75b38faadcd24bec177c308ebd5304f060ec7a363e318af9bfaaa5e07be972cfc1ea4e21b47637fcdb2dfc53130c40a8efed5defc408a04fb4c8ed7016461c-combine
5eecdaf48460cde5544f9fac410016bc2fe4c1b4d23666c075b8339e1c4c24831b75b38faadcd24bec177c308ebd5304922cbdef3e3c42f83239de6d0f35a8b76f0e38934cc5170f7a908ec12140fb0af6590c72bcf1ba6f4fb4c8ed7016461c-2025-12-29-19-15-53

Subject Feature Preservation

Input ImageOutput Image
5eecdaf48460cde5544f9fac410016bc2fe4c1b4d23666c075b8339e1c4c24831b75b38faadcd24bec177c308ebd53043e6c778a593da070988fa11b14a85d95e1c17d91f51ae21f2f94f7e5f5f32208a0ad2896cb2b0a024fb4c8ed7016461c-2025-12-29-20-00-22
5eecdaf48460cde5544f9fac410016bc2fe4c1b4d23666c075b8339e1c4c24831b75b38faadcd24bec177c308ebd5304c29923066754bb698349034eb20df1ce0b5ae32ae31d57bb753bd259e87d69dd01cab9fe9f470e1a4fb4c8ed7016461c-2025-12-29-20-00-21
5eecdaf48460cde5544f9fac410016bc2fe4c1b4d23666c075b8339e1c4c24831b75b38faadcd24bec177c308ebd5304448a972b9f2ee7a7aadcc61495f4975a049f009e7721cbc833dc3a8005b1b026a54eaaec109d73484fb4c8ed7016461c-2025-12-29-20-00-21
5eecdaf48460cde5544f9fac410016bc2fe4c1b4d23666c075b8339e1c4c24831b75b38faadcd24bec177c308ebd5304cc1b4a509823c5fb5e60999898811f8b51d7419220a118c9ff82110bc9525725a9ad7338f75985794fb4c8ed7016461c-2025-12-29-20-00-21

Detection and Segmentation

Input ImageOutput Image
5eecdaf48460cde5544f9fac410016bc2fe4c1b4d23666c075b8339e1c4c24831b75b38faadcd24bec177c308ebd5304b025e74206dc2cec5c2e587c3fe6fb135293836c9479220355470da15476dc934b26018061e9db0b4fb4c8ed7016461c-2025-12-29-19-54-33
5eecdaf48460cde5544f9fac410016bc2fe4c1b4d23666c075b8339e1c4c24831b75b38faadcd24bec177c308ebd530451385eb561b49b0fe1f2169526b6a7e15bd78940def3c640c801511c349f6df35dceb72f4d3755f94fb4c8ed7016461c-2025-12-29-19-54-33
5eecdaf48460cde5544f9fac410016bc2fe4c1b4d23666c075b8339e1c4c24831b75b38faadcd24bec177c308ebd530440256f9add4113787af5d4f3a55469b38ef2422f018076640eb7cb552584c02ee729fcb23fec3bca4fb4c8ed7016461c-2025-12-29-19-54-33
5eecdaf48460cde5544f9fac410016bc2fe4c1b4d23666c075b8339e1c4c24831b75b38faadcd24bec177c308ebd5304f0612d67f5c810ebef958385624ebd17323047aa5d00465d0e35257de5a2ea49d4b375d2e57693fa4fb4c8ed7016461c-2025-12-29-19-54-32

Extract Elements

Input ImageOutput Image
5eecdaf48460cde5544f9fac410016bc2fe4c1b4d23666c075b8339e1c4c24831b75b38faadcd24bec177c308ebd53046b83761f1ab18c40e144f5db2b388e5f865ba9a5961d98b2710ce177c6a0f4baff63fe52259c44364fb4c8ed7016461c-2025-12-29-19-48-27
5eecdaf48460cde5544f9fac410016bc2fe4c1b4d23666c075b8339e1c4c24831b75b38faadcd24bec177c308ebd53048e2a0d1d2805d92ba8d45a3bd1368528dd76f517b21ad1f545eb4097610838497cbdb5196da94ff54fb4c8ed7016461c-2025-12-29-19-48-27

Text Editing

Input ImageOutput Image
5eecdaf48460cde5544f9fac410016bc2fe4c1b4d23666c075b8339e1c4c24831b75b38faadcd24bec177c308ebd530490f493eca22f34f0197173ddfdef17a04b34cb94813178b9d4eee36d246d3530a3e2fc6258cca0694fb4c8ed7016461c-2025-12-29-19-28-35
5eecdaf48460cde5544f9fac410016bc2fe4c1b4d23666c075b8339e1c4c24831b75b38faadcd24bec177c308ebd5304fe77776567f4ef79cb621289a6fdaa981f3364fe4c7c56265403b5d9d5ac43eaf5931f62db14952f4fb4c8ed7016461c-2025-12-29-19-28-35
5eecdaf48460cde5544f9fac410016bc2fe4c1b4d23666c075b8339e1c4c24831b75b38faadcd24bec177c308ebd530476e971380812b1b9dbeac68272a27057175499fe84f0781c7b6fa6535f438c67f3556acc8c7324394fb4c8ed7016461c-2025-12-29-19-28-35
5eecdaf48460cde5544f9fac410016bc2fe4c1b4d23666c075b8339e1c4c24831b75b38faadcd24bec177c308ebd53047be52c6f41edecdefa77f0d93335d1492f1821b47dff7a1b08f60e99bdafcc84c31e3658fc593c904fb4c8ed7016461c-2025-12-29-19-28-35
5eecdaf48460cde5544f9fac410016bc2fe4c1b4d23666c075b8339e1c4c24831b75b38faadcd24bec177c308ebd5304fdb284f8d5c8ead814d11890da1a49411a6d9d41ad1bb2a4bf0b93d0bee5d792e8f5b419a3da9d534fb4c8ed7016461c-2025-12-29-19-28-34
5eecdaf48460cde5544f9fac410016bc2fe4c1b4d23666c075b8339e1c4c24831b75b38faadcd24bec177c308ebd5304df1c8787530497f4cc3bee0b84d3ba51d0353fceb8d0518ded6a25e8c0ddfec714f719154ac1c9354fb4c8ed7016461c-2025-12-29-19-28-34

Lens and Viewpoint Editing

Input ImageOutput Image
image (2)-2025-12-29-19-42-44
image (3)-2025-12-29-19-42-44
5eecdaf48460cde5544f9fac410016bc2fe4c1b4d23666c075b8339e1c4c24831b75b38faadcd24bec177c308ebd5304a53988b2efdd2fb6b95cb3b1b02701e6ff2c4902170b1ee230a9b4e3726a891c93646d68b821de294fb4c8ed7016461c-2025-12-29-19-42-43
5eecdaf48460cde5544f9fac410016bc2fe4c1b4d23666c075b8339e1c4c24831b75b38faadcd24bec177c308ebd530428783dee341e41eb06234dfb75bd149d774f4850000123559a98bcd7ece97dc4a6c3cefa983ae8ac4fb4c8ed7016461c-2025-12-29-19-42-43

Input instructions

Input image specifications

Specificationwan2.7-image-pro, wan2.7-imagewan2.6-imagewan2.5-i2i-preview
Number of input images0 to 9 (0 for text-to-image mode)Image editing: 1 to 4 / Mixed media: 0 to 11 to 3
Image formatJPEG, JPG, PNG (alpha channel not supported), BMP, WEBPJPEG, JPG, PNG (alpha channel not supported), BMP, WEBPJPEG, JPG, PNG (alpha channel not supported), BMP, WEBP
Image dimensions[240, 8000] pixels[240, 8000] pixels[384, 5000] pixels
File size≤ 20 MB≤ 10 MB≤ 10 MB
Aspect ratio[1:8, 8:1]No limit[1:4, 4:1]

Image input order

Input image 1Input image 2Output image
image (19)-转换自-png
Image 1
image (20)-转换自-png
Image 2
04e0fc39-7ad6-41e0-9df9-1f69ac3ce825-转换自-png
Prompt: Move Image 1 onto Image 2
36ed450d-bd54-4169-b13f-3d0f26d9d360-转换自-png
Prompt: Move Image 2 onto Image 1

Methods for providing images

Provide images in the following ways:
# Use a publicly accessible image URL
image_url = "https://example.com/your-image.png"
# In curl, pass the URL directly in the JSON body
"image": "https://example.com/your-image.png"
import os
import base64
import mimetypes

# The format is data:{mime_type};base64,{base64_data}
def encode_file(file_path):
    mime_type, _ = mimetypes.guess_type(file_path)
    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}"
        
        
# Call the encoding function. Replace "/path/to/your/image.png" with the path to your local image file. Otherwise, the code will not run.
image = encode_file("/path/to/your/image.png")
# Local file path format: file:// + absolute path
# Linux/macOS example:
image_url = "file://" + "/path/to/your/image.png"
# Windows example:
image_url = "file:///" + "C:/path/to/your/image.png"

# Relative path example:
image_url = "file://" + "./your-image.png"
This method is only supported by the SDK. Curl requests require a public URL or Base64 encoding.

Key capabilities

1. Instruction following (prompts)

The parameters are messages.content.text or input.prompt (required), and negative_prompt (optional).
Parameterwan2.7-image-pro, wan2.7-imagewan2.6-imagewan2.5-i2i-preview
textRequired, up to 5000 charactersRequired, up to 2000 charactersNot supported
promptNot supportedNot supportedRequired, up to 2000 characters
negative_promptNot supportedSupported, up to 500 charactersSupported, up to 500 characters

2. Enable prompt rewriting

The parameter is parameters.prompt_extend (bool, default true ). This feature automatically expands and optimizes short prompts to improve output image quality. However, enabling it adds extra processing time.
Parameterwan2.7-image-pro, wan2.7-imagewan2.6-imagewan2.5-i2i-preview
prompt_extendNot supportedSupported (edit mode only)Supported

3. Set output image resolution

The parameter is parameters.size (string), formatted as "width*height" .
Parameterwan2.7-image-pro, wan2.7-imagewan2.6-imagewan2.5-i2i-preview
sizeOption 1: Specify output resolution (recommended) In edit mode (at least one input image provided), choose from these resolution presets: 1K , 2K (default). 1K : Output has approximately 1024×1024 total pixels, preserving the aspect ratio of the last input image. 2K : Output has approximately 2048×2048 total pixels, preserving the aspect ratio of the last input image. Option 2: Specify exact width and height in pixels Total pixels must be between 768×768 and 2048×2048, with an aspect ratio between 1:8 and 8:1. Only wan2.7-image-pro in text-to-image scenarios supports 4K resolution.Option 1: Match input image aspect ratio (recommended) In edit mode ( enable_interleave=false ), choose from these resolution presets: 1K (default), 2K . 1K : Output has approximately 1280×1280 total pixels, preserving the aspect ratio of the last input image. 2K : Output has approximately 2048×2048 total pixels, preserving the aspect ratio of the last input image. Option 2: Specify exact width and height in pixels Total pixels must be between 768×768 and 2048×2048, with an aspect ratio between 1:4 and 4:1. The pixel value of the actual output image is a multiple of 16 that is closest to the specified value.Only exact width and height in pixels are supported Total pixels must be between 768×768 and 1280×1280, with an aspect ratio between 1:4 and 4:1. If you do not specify size , the system generates an image with a total of 1280*1280 pixels by default, with the same aspect ratio as the last input image.

4. Interactive precise editing

You can use the parameters.bbox_list parameter to define interactive editing regions. The format is List[List[List[int]]] . This lets you select specific objects or areas in the image for more accurate edits. Only wan2.7-image-pro and wan2.7-image support this feature. For example, if the input includes 3 images, and Image 2 has no selections while Image 1 has two selections, you would use the following:
[
  [[0, 0, 12, 12], [25, 25, 100, 100]],  # Image 1 (2 boxes)
  [],                                    # Image 2 (no boxes)
  [[10, 10, 50, 50]]                    # Image 3 (1 box)
]

Billing and Rate Limits

  • For free quota and pricing details, see Pricing.
  • For rate limit details, see Rate Limits.
  • Billing details: You are billed for each successfully generated image. Charges are incurred only when the API returns a task_status of SUCCEEDED and an image is generated. You are not charged for failed calls or processing errors, and they do not consume your free quota.

API Reference

For information about input and output parameters, see Wanxiang - Image Generation and Editing (for wan2.7-image and wan2.6-image) and Wanxiang - General Image Editing 2.5 API Reference.