-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-image.php
More file actions
49 lines (42 loc) · 1.72 KB
/
generate-image.php
File metadata and controls
49 lines (42 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* AIGate API — Generate Image Example
* Docs: https://aigatecloud.com/docs/
*
* Replace YOUR_KEY_HERE with your real key from aigatecloud.com
* Free plan: 100 credits (each image costs 10 credits)
*/
$apiKey = getenv('AIGATE_KEY') ?: 'sk-aigate-YOUR_KEY_HERE';
$baseUrl = getenv('AIGATE_BASE_URL') ?: 'https://api.aigatecloud.com/v1';
$payload = [
'prompt' => 'luxury lifestyle, gold aesthetic, rich vibes',
'aspect_ratio' => '9:16', // 9:16 | 16:9 | 1:1 | 4:5
'use_case' => 'viral_background', // viral_background | ads_product | portrait | thumbnail
'style' => 'luxury', // luxury | minimal | bold | cinematic | artistic
];
$ch = curl_init($baseUrl . '/generate/image');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json',
],
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$result = json_decode($body, true);
if (!$result || !($result['ok'] ?? false)) {
echo "Error ($status): " . ($result['error'] ?? $body) . PHP_EOL;
if ($status === 401) {
echo "→ Register free at https://aigatecloud.com to get a real API key." . PHP_EOL;
}
exit(1);
}
echo "✓ Image generated!" . PHP_EOL;
echo " Source: " . $result['source'] . " (" . $result['provider'] . ")" . PHP_EOL;
echo " URL: " . $result['asset']['url'] . PHP_EOL;
echo " Ratio: " . $result['asset']['aspect_ratio'] . PHP_EOL;
echo " Credits: −" . $result['credits_charged'] . " (balance: " . $result['credits_balance'] . ")" . PHP_EOL;