php调用阿里通义万相api实现AnyText图文融合代码

代码语言:php

所属分类:其他

代码描述:php调用阿里通义万相api实现AnyText图文融合代码,支持图文生成和文字编辑功能,可广泛应用于电商海报、Logo设计、创意涂鸦、表情包、儿童绘本等诸多场景。

代码标签: php 调用 阿里 通义 万相 api AnyText 图文 融合 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<?php
function submitTextGenerationJob($apiKey, $prompt, $maskImageUrl) {
    $url = 'https://dashscope.aliyuncs.com/api/v1/services/aigc/anytext/generation';
    
    $headers = [
        'Content-Type: application/json',
        'Authorization: Bearer ' . $apiKey,
        'X-DashScope-Async: enable'
    ];

    $postData = [
        'model' => 'wanx-anytext-v1',
        'input' => [
            'prompt' => $prompt,
            'mask_image_url' => $maskImageUrl
        ],
        'parameters' => [
            // You can add optional parameters here if needed
        ]
    ];
    
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($ch);
    if (!$response) {
        die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
    }
    curl_close($ch);

    return json_decode($response, true);
}

function getTextGenerationResult($apiKey, $taskId) {
    $url = "https://dashscope.aliyuncs.com/api/v1/tasks/$taskId";
    
    $headers = [
        'Authorization: Bearer ' . $apiKey
    ];
    
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRA.........完整代码请登录后点击上方下载按钮下载查看

网友评论0