php调用阿里通义万相api实现涂鸦作画代码

代码语言:php

所属分类:其他

代码描述:php调用阿里通义万相api实现涂鸦作画代码,通过手绘任意内容加文字描述,即可生成精美的涂鸦绘画作品,作品中的内容在参考手绘线条的同时,兼顾创意性和趣味性。涂鸦作画支持扁平插画、油画、二次元、3D卡通和水彩5种风格,可用于创意娱乐、辅助设计、儿童教学等场景。

代码标签: php 调用 阿里 通义 万相 api 涂鸦 作画 代码

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

<?php

function submitImageSynthesisJob($apiKey, $sketchImageUrl, $prompt) {
    $url = 'https://dashscope.aliyuncs.com/api/v1/services/aigc/image2image/image-synthesis/';

    $headers = [
        'Content-Type: application/json',
        'Authorization: Bearer ' . $apiKey,
        'X-DashScope-Async: enable'
    ];

    $postData = [
        'model' => 'wanx-sketch-to-image-lite',
        'input' => [
            'sketch_image_url' => $sketchImageUrl,
            'prompt' => $prompt
        ],
        'parameters' => [
            'size' => '768*768',
            'n' => 2,
            'style' => '<watercolor>',
            'sketch_extraction' => false,
            'sketch_color' => [[0, 0, 0], [123, 123, 123]]
        ]
    ];
    
    $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 getImageSynthesisResult($apiKey, $taskId) {
    $url = "https://dashscope.aliyuncs.com/api/v1/tasks/$taskId";

    $h.........完整代码请登录后点击上方下载按钮下载查看

网友评论0