PHP İle OpenAI API Kullanarak Yapay Görsel Oluşturmak

24 Haziran 2023 186 Okuma süresi: 1 dakika
function getImg($token, $text){
    $curl = curl_init();

    curl_setopt_array($curl, array(
        CURLOPT_URL => 'https://api.openai.com/v1/images/generations',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS =>'{
            "prompt": "'.$text.'",
            "n": 1,
            "size": "512x512"
            }',

        CURLOPT_HTTPHEADER => array(
            'Authorization: Bearer  '.$token,
            'Content-Type: application/json'
        ),
    ));
    $response = curl_exec($curl);
    curl_close($curl);
    return json_decode($response, true);
}

Benzer makaleler