php调用Stable-Diffusion官方api实现图片放大变清晰示例代码

代码语言:php

所属分类:其他

代码描述:php调用Stable-Diffusion官方api实现图片放大变清晰示例代码

代码标签: php 调用 Stable Diffusion 官方 api 图片 放大 清晰 示例 代码

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

<?php
//申请地址:https://platform.stability.ai/account/keys
$_apikey = "";
// Initialize a cURL session
$ch = curl_init();

// Set up the file to be sent via POST
$imageFilePath = '/data/wwwroot/default/asset/man.png';

$imageFile = new CURLFile($imageFilePath);


// Set the cURL options for the request
curl_setopt($ch, CURLOPT_URL, "https://api.stability.ai/v2beta/stable-image/upscale/creative");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, true); // Corresponds to the '-f' flag in the curl command
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Authorization: Bearer ".$_apikey // Replace 'sk-MYAPIKEY' with your actual API key
]);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
    'image' => $imageFile,
    'prompt' => "cute fluffy white kitten sitting in a rainforest, pastel colors",
    'output_format' => 'webp',
]);


// Execute the cURL session
$response = curl_exec($ch);

// Check for errors
if (curl_errno($ch)) {
    echo curl_error($ch);

    curl_close($ch);
    exit();
}

// Close the file pointer and clean up

curl_close($ch);

echo $response;
//返回generation_id {"id": "a6dc6c6e20acda010fe14d71f180658f2896ed9b4ec25aa99a6ff06c796987c4"}

//定期检测是否完成;getaskid
function getaskid($generation_id, $_apikey, $saveToFilePath) {
    // Set the variables
   
    $u.........完整代码请登录后点击上方下载按钮下载查看

网友评论0