'No image file received', 'debug' => $debug]); exit; } $output_height = $_POST['output_height'] ?? ''; $model = $_POST['model'] ?? ''; $face_enhancement = isset($_POST['face_enhancement']) && $_POST['face_enhancement'] === 'on' ? true : false; $debug[] = "Output Height: $output_height"; $debug[] = "Model: $model"; $debug[] = "Face Enhancement: " . ($face_enhancement ? 'true' : 'false'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.topazlabs.com/image/v1/enhance/async'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Accept: application/json', 'X-API-Key: ' . API_TOKEN ]); $postFields = [ 'image' => new CURLFile($image['tmp_name'], $image['type'], $image['name']), 'output_height' => $output_height, 'output_format' => 'jpeg', 'crop_to_fill' => 'false', 'face_enhancement' => $face_enhancement ? 'true' : 'false' ]; if ($model !== 'Auto') { $postFields['model'] = $model; } curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); $debug[] = "Sending request to API"; $debug[] = "Post Fields: " . json_encode($postFields); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $debug[] = "API Response Code: $httpCode"; if ($response === false) { $debug[] = "cURL Error: " . curl_error($ch); echo json_encode(['error' => 'cURL error', 'debug' => $debug]); } else { $debug[] = "API Response: $response"; $result = json_decode($response, true); if (json_last_error() === JSON_ERROR_NONE) { $result['debug'] = $debug; echo json_encode($result); } else { echo json_encode(['error' => 'Invalid JSON response', 'raw_response' => $response, 'debug' => $debug]); } } curl_close($ch); } else { echo json_encode(['error' => 'Invalid request method', 'debug' => ['Received non-POST request']]); }