图生图 图生图
接口介绍

功能简介

CloudImageToImage 是云端图生图服务,能够以一张源图片为基础,结合文字描述生成全新的图片。该服务支持多种模型,可根据不同的提示词对源图片进行风格转换、内容编辑或创意扩展。

适用场景

  • 创意设计:基于素材图片生成多种风格变体
  • 电商设计:为商品图片生成不同风格背景或效果
  • 艺术创作:将照片转换为不同艺术风格的作品
  • 内容配图:根据已有图片素材生成新的配图
  • 图片编辑:通过文字描述对图片进行智能编辑和修改

功能特性

  • 多种模型:支持多种图像生成模型(如 qwen-image-edit 等)
  • 灵活控制:通过 prompt 精确控制生成效果
  • 参数配置:支持自定义尺寸等参数
  • 异步处理:提交任务后轮询获取生成结果
  • 示例代码:提供 PHP 示例代码,方便快速集成

资费标准

  • 图生图:按实际用量计费
接口计费 VIP特权
100 点数 / ¥9.99
1,000 点数 / ¥90.00
10,000 点数 / ¥890.00
100,000 点数 / ¥8800.00
暂无VIP特权
接口文档

1. 接口基础

使用前请阅读 接口基础

2. 任务提交(异步)

请求地址

[POST] https://api.tecmz.com/open_api/image_to_image/queue

请求参数

参数 必须 类型 说明
model string 使用的模型
prompt string 生成图片的提示词描述
image string 源图片链接,可外网访问,如 http://example.com/image.jpg
param object 参数对象,包含尺寸等配置,如 {"size": "1024x1024"}

返回

{
    "code": 0,
    "msg": "ok",
    "data": {
        // 任务ID
        "taskId": "1"
    }
}

3. 任务查询

请求地址

[POST] https://api.tecmz.com/open_api/image_to_image/query

请求参数

参数 必须 类型 说明
taskId string 任务ID

返回

{
    "code": 0,
    "msg": "ok",
    "data": {
        // 任务状态:RUNNING | SUCCESS | FAIL
        "status": "SUCCESS",
        "result": {
            // 生成的图片URL
            "imageUrl": "https://example.com/generated-image.jpg"
        }
    }
}

4. 示例代码

PHP

<?php
// 提交任务
$data = [
    'model' => 'qwen-image-edit',
    'prompt' => '将这张图片变成科幻风格',
    'image' => 'https://example.com/source-image.jpg',
    'param' => [
        'size' => '1024x1024'
    ]
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://your-domain.com/open_api/image_to_image/queue');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'Authorization: Bearer YOUR_API_TOKEN'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$result = json_decode($response, true);

if ($result['code'] == 0) {
    $taskId = $result['data']['taskId'];
    
    // 查询结果
    while (true) {
        $queryData = ['taskId' => $taskId];
        curl_setopt($ch, CURLOPT_URL, 'https://your-domain.com/open_api/image_to_image/query');
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($queryData));
        
        $queryResponse = curl_exec($ch);
        $queryResult = json_decode($queryResponse, true);
        
        if ($queryResult['data']['status'] == 'SUCCESS') {
            $imageUrl = $queryResult['data']['result']['imageUrl'];
            echo "生成成功,图片地址:$imageUrl\n";
            break;
        } elseif ($queryResult['data']['status'] == 'FAIL') {
            echo "生成失败\n";
            break;
        }
        
        sleep(5); // 等待5秒后重试
    }
}

curl_close($ch);
展开
QQ
微信
公众号
客服