'Missing parameters']); exit; } $cacheDir = __DIR__ . '/../cache/test-results/'; if (!file_exists($cacheDir)) mkdir($cacheDir, 0755, true); $hash = md5($testName . $resultText . date('Y-m-d')); $cacheFile = $cacheDir . $hash . '.png'; if (file_exists($cacheFile)) { echo json_encode(['image_url' => '/cache/test-results/' . $hash . '.png']); exit; } // Kandinsky 2.2 API через Segmind $apiKey = "YOUR_SEGMIND_API_KEY"; // Замените на ваш ключ $shortResult = mb_substr(strip_tags($resultText), 0, 200); $prompt = "Create a mystical astrology-themed share image for a quiz result. Test name: " . $testName . ". Key result: " . $shortResult . ". Style: Dark purple cosmic background, golden zodiac symbols, mystical atmosphere, elegant design, inspirational mood, social media share format (1200x630). Text overlay area ready, professional astrology branding."; $ch = curl_init("https://api.segmind.com/v1/kandinsky2.2-txt2img"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "x-api-key: $apiKey", "Content-Type: application/json" ]); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([ "prompt" => $prompt, "negative_prompt" => "low quality, blurry, deformed, text error, watermark", "samples" => 1, "num_inference_steps" => 30, "img_width" => 1200, "img_height" => 630, "prior_steps" => 25, "seed" => rand(1, 9999999), "base64" => false ])); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode === 200 && $response) { file_put_contents($cacheFile, $response); echo json_encode(['image_url' => '/cache/test-results/' . $hash . '.png']); } else { // Возвращаем SVG-заглушку $svgFile = $cacheDir . $hash . '.svg'; $svgContent = ' ' . htmlspecialchars($testName) . ' Результат теста ⭐ Твой Зодиак ⭐ '; file_put_contents($svgFile, $svgContent); echo json_encode(['image_url' => '/cache/test-results/' . $hash . '.svg']); } ?>