文生图 文生图
接口介绍

功能简介

CloudTextToImage 是云端文生图服务,能够根据文字描述直接生成全新的图片。基于先进的 AI 图像生成模型,只需输入一段描述性的提示词(prompt),即可生成与描述相匹配的高质量图片。

适用场景

  • 创意设计:快速将创意想法可视化为图片
  • 内容创作:为文章、社交媒体生成配图
  • 广告设计:快速生成广告素材的多个方案
  • 产品设计:辅助产品概念设计和原型展示
  • 艺术探索:探索不同艺术风格和创意表达

功能特性

  • 多种模型:支持多种图像生成模型
  • 精准控制:通过 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/text_to_image/queue

请求参数

参数 必须 类型 说明
model string 使用的模型
prompt string 生成图片的提示词描述
param object 参数对象,包含尺寸等配置,如 {"size": "1024x1024"}

返回

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

3. 任务查询

请求地址

[POST] https://api.tecmz.com/open_api/text_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',
    'prompt' => '一只可爱的小猫在花园里玩耍',
    'param' => [
        'size' => '1024x1024'
    ]
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://your-domain.com/open_api/text_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/text_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
微信
公众号
客服