Skip to main content

Qwen-Image-Edit

The Qwen-Image-Edit model supports multi-image input and multi-image output. It can precisely modify text in images, add, remove, or move objects, change subject poses, transfer image styles, and enhance image details.

QuickStart

Before making calls, you need to obtain and configure an API Key, and then configure the API Key as an environment variable. To make calls through the SDK, please install the DashScope SDK. Currently, the SDK supports Python and Java.
Please replace DASHSCOPE_API_HOST in the sample code with the obtained API Host.
  • Python
  • Java
  • curl
import os
import base64
import mimetypes
import dashscope

# This configuration is for the Singapore region. Replace {WorkspaceId} with your actual workspace ID. The region value varies by region.
# If the environment variable is not configured, replace the following line with your Model Studio API key: api_key="sk-xxx"
# API keys differ by region. Get an API key: https://www.alibabacloud.com/help/model-studio/get-api-key
client = dashscope.Client(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    workspace="{WorkspaceId}",
    region="ap-southeast-1",
)

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}"

# [Method 1] Use a public image URL
image_url = "https://alidocs.oss-cn-zhangjiakou.aliyuncs.com/res/yBRq1ZPYEaXdyOdv/img/33a80a19-7ac7-4c64-b0fa-7d685b7046a0.png"

# [Method 2] Use a Base64-encoded image
# image_url = encode_file("./your_image.png")

response = client.multimodal.chat.create(
    model="qwen-image-3.0-pro",
    messages=[{
        "role": "user",
        "content": [
            {"image": image_url},
            {"text": "帮我生成一张充满高级感的都市风格女性写真,画面中人物完美保留输入图片中这位年轻女性的面部特征与一头柔顺的黑色长发。人物换上一套彰显高雅气质的都市职场穿搭,场景设定在一家装修现代简约的高端咖啡店内。"}
        ]
    }],
    parameters={"prompt_extend": True},
)

# SDK 2.0: Read generated results from message.content_parts; image parts have the form {"image": URL, "type": "image"}
message = response.choices[0].message
for part in (message.content_parts or []):
    if "image" in part:
        print(f"Generated image URL: {part['image']}")
# 需要安装requests以下载图像: pip install requests
import requests

def download_image(image_url, save_path='output.png'):
    try:
        response = requests.get(image_url, stream=True, timeout=300)  # 设置超时
        response.raise_for_status()  # 如果HTTP状态码不是200,则引发异常
        with open(save_path, 'wb') as f:
            for chunk in response.iter_content(chunk_size=8192):
                f.write(chunk)
        print(f"图像已成功下载到: {save_path}")

    except requests.exceptions.RequestException as e:
        print(f"图像下载失败: {e}")

image_url = "https://dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com/xxx.png?Expires=xxx"
download_image(image_url, save_path='output.png')

Model selection recommendations

  • qwen-image-3.0-pro (Ultimate performance): Qwen-Image 3.0 Ultimate Edition, with comprehensively upgraded image generation and editing capabilities and stronger text rendering, realistic texture, and semantic adherence.
  • qwen-image-2.1-pro (Best balance of speed, quality, and cost): Supports passing in up to 10 reference images, automatically decides whether to output a normal image or an image with a transparent channel based on the prompt, and does not support negative_prompt.
  • qwen-image-2.1-turbo (Ultimate cost-effectiveness): Delivers the best overall cost-effectiveness in the Qwen-Image series, supports passing in up to 10 reference images, automatically decides whether to output a normal image or an image with a transparent channel based on the prompt, and does not support negative_prompt.
  • qwen-image-3.0: Qwen-Image 3.0 Standard Edition, balancing quality and speed.
For models supported in each region, see the model list in the Model Studio console.

Input description

Input images (messages)

messages is an array and must contain only one object. The object must contain the role and content properties. Specifically, role must be set to user, and content must contain both image and text (an editing instruction). The qwen-image-3.0 series supports 1 to 3 images, and the qwen-image-2.1 series supports 1 to 10 images. Input images must meet the following requirements:
  • Image formats: JPG, JPEG, PNG, BMP, TIFF, WEBP, and GIF.
    Output images are in PNG format. For animated GIF images, only the first frame is processed.
  • Image resolution: For best results, both the width and height of images are recommended to be between 384 and 3,072 pixels. A resolution that is too low may result in blurry generated output, while one that is too high increases processing time.
  • File size: A single image file must not exceed 10 MB.
"messages": [
    {
        "role": "user",
        "content": [
            { "image": "图1的公网URL或Base64数据" },
            { "image": "图2的公网URL或Base64数据" },
            { "image": "图3的公网URL或Base64数据" },
            { "text": "您的编辑指令,例如:'图1中的女生穿着图2中的黑色裙子按图3的姿势坐下'" }
        ]
    }
]

Image input order

When multiple images are input, the image order is defined by their order in the array. Therefore, the image numbers referenced in the prompt must correspond one-to-one with the order in the image array, for example: the first image in the array is "Image 1", the second is "Image 2", or use markers such as "[Image 1]" and "[Image 2]".
{
    "content": [
        {"text": "编辑指令,如:将图1中的闹钟放置到图2的餐桌的花瓶旁边位置"},
        {"image": "https://example.com/image1.png"},
        {"image": "https://example.com/image2.png"}
    ]
}

Input image

Output 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

Image Input Methods

Public URL
  • Provide a publicly accessible image address that supports the HTTP or HTTPS protocol.
  • Example value: https://xxxx/img.png.
Base64 Encoding Convert the image file into a Base64-encoded string and assemble it in the format: data:{mime_type};base64,{base64_data}.
  • {mime_type}: the media type of the image, which must match the file format.
  • {base64_data}: the Base64-encoded string of the file.
  • Example value: data:image/jpeg;base64,GDU7MtCZz... (truncated for demonstration only)
For the complete sample code, see Python SDK calls and Java SDK calls.

More Parameters

You can adjust the generation results with the following optional parameters:
  • n: the number of output images (default 1, up to 6). n directly affects the fee.
  • negative_prompt: describes content you do not want to appear (such as "blurry" or "extra fingers") to help optimize generation quality. The qwen-image-2.1 series does not support this parameter; describe it in the positive prompt instead.
  • size: the output resolution, in the format width*height. The qwen-image-3.0 series and qwen-image-2.1 series support 512*512 to 2048*2048 (aspect ratio from 1:8 to 8:1); if not specified, the model automatically recommends one.
  • prompt_extend: intelligent prompt rewriting (enabled by default). It is recommended for concise prompts; disable it for detailed prompts or latency-sensitive scenarios.
  • seed: the random seed; using the same value keeps generation results relatively stable.
  • watermark: whether to add a watermark (disabled by default).
For the complete parameter list, see Qwen Image Edit API.

Effect Overview

Multi-image Fusion

Input image 1

Input image 2

Input image 3

Output image

image83

image103

1

2

The girl in image 1 wears the necklace from image 2 and carries the bag from image 3 on her left shoulder

Subject Consistency Preservation

Input image

Output image 1

Output image 2

Output image 3

image5

image4

Change to an ID photo with a blue background; the person wears a white shirt, a black suit, and a striped tie

image6

The person wears a white shirt, a gray suit, and a striped tie, touching the tie with one hand, against a light-colored background

image7

The person wears a black hoodie featuring the words "Qwen Image" in a bold brush font, leaning against a railing with sunlight shining on her hair, with a bridge and the sea behind her

image12

image13

Place this air conditioner in the living room, next to the sofa

image14

Add mist coming out of the air conditioner vent, extending all the way to the sofa, and add green leaves.

image15

Add white handwritten text "Natural Fresh Air, Breathe Freely" at the top

Sketch Creation

Input image

Output image

image42

image43

Generate an image that matches the refined shape outlined in image 1 and follows this description: a young woman smiling on a sunny day, wearing a pair of round brown sunglasses with leopard-print frames. Her hair is neatly pulled up, she wears pearl earrings, a dark blue scarf with a purple star pattern around her neck, and a black leather jacket.

image44

Generate an image that matches the refined shape outlined in image 1 and follows this description: an elderly man smiling at the camera, his face covered in wrinkles, his hair messy in the wind, wearing a pair of round reading glasses. Around his neck is a worn red scarf with a star pattern. He is wearing a padded cotton coat.

Cultural and creative design

Input image

Output image

图片 1

image23

Let this bear sit under the moon (represented by a light gray crescent moon outline on a white background), holding a guitar, with small stars and poem bubbles such as “Be Kind” floating around.

image22

Print this pattern on a T-shirt and a handheld paper bag. A female model is displaying these items. The girl also wears a peaked cap with the words "Be kind" on it.

image21

A hyper-realistic 1/7 scale character model, designed as a finished commercial product, placed on an iMac desk with a white keyboard. The model stands on a clean, round, transparent acrylic base with no labels or text. Professional studio lighting highlights the sculpted details. On the iMac screen in the background, the ZBrush modeling process of the same model is shown. Next to the model, place a packaging box with a transparent window on the front, showing only the transparent plastic shell inside, slightly taller than the model and reasonably sized to hold it.

image

This bear is wearing a spacesuit, pointing into the distance with its finger

image

This bear is wearing an ornate dance dress, with arms outstretched, performing an elegant dance move

image

This bear is wearing sportswear, holding a basketball in its hand, with one leg bent

Generate images from a depth map

Input image

Output image

image36

image37

Generate an image that matches the depth map outlined in Figure 1 and follows this description: a blue bicycle parked in an alley by the street, with a few weeds growing out of stone crevices in the background

image38

Generate an image that matches the depth map outlined in Figure 1 and follows this description: a red, worn-out bicycle parked on a muddy path, with a dense primeval forest in the background

Generate images from keypoints

Input image

Output image

image40

image41

Generate an image that matches the human pose outlined in Figure 1 and follows this description: a beautiful Chinese woman wearing Hanfu, holding an oil-paper umbrella in the rain, with a Suzhou garden in the background.

image39

Generate an image that matches the human pose outlined in Figure 1 and follows this description: a young man standing on a subway platform, wearing a baseball cap on his head, dressed in a T-shirt and jeans. Behind him, a train speeds past.

Text editing

Input image

Output image

Input image

Output image

image

image

Replace 'HEALTH INSURANCE' on the Scrabble tile with 'Tomorrow will be better'

image

image

Change the phrase “Take a Breather” on the note to “Relax and Recharge”

Input image

Output image

image53

image45

Change “Qwen-Image” to a black ink-drip font

image46

Change “Qwen-Image” to a black handwritten font

image49

Change “Qwen-Image” to a black pixel font

image54

Change “Qwen-Image” to red

image57

Change “Qwen-Image” to a blue-purple gradient

image59

Change “Qwen-Image” to candy colors

image63

Change the “Qwen-Image” material to metal

image64

Change the “Qwen-Image” material to clouds

image67

Change the “Qwen-Image” material to glass

Add, remove, and modify

Capabilities

Input image

Output image

Add elements

image

image

Add a small wooden sign in front of the penguin that reads “Welcome to Penguin Beach”.

Delete elements

image

image

Remove hair from the plate

Viewpoint conversion

Input image

Output image

Input image

Output image

image

image

Obtain a front view

image

image

Facing the left side

image

image

Obtain a rear view

image

image

Facing the right side

Old photo processing

Capabilities

Input image

Output image

Old photo restoration and colorization

image

image

Restore old photos, remove scratches, reduce noise, enhance details, high resolution, realistic visuals, natural skin tones, clear facial features, and no distortion.

image31

image32

Intelligently colorize images based on their content, making them more vivid

API reference

For the API input and output parameters, see Qwen-Image-Edit.

Error codes

If a model call fails and returns an error message, see Error codes for troubleshooting.

FAQ

Q: Which languages does the Qwen image editing model support?

A: Simplified Chinese and English are currently officially supported. You can try other languages on your own, but the results may be uncertain.

Q: How do I view model usage?

A: One hour after the model call is complete, go to the Monitoring (Singapore) or Monitoring (Beijing) page to view metrics such as the number of model calls and the success rate. For more information, see Bill query and cost management.

Q: How do I obtain the access domain whitelist for image storage?

A: Images generated by the model are stored in Alibaba Cloud OSS, and the API returns a temporary public URL. If you need to configure a firewall whitelist for this download address, note that the underlying storage dynamically changes based on business conditions. To prevent expired information from affecting access, this documentation does not provide a fixed OSS domain whitelist. If you have security control requirements, contact your account manager to obtain the latest list of OSS domains. For more questions, see Image generation FAQ.