- PHP-based web interface for image upscaling using Topaz Labs API - Multiple image upload with batch processing support - AI model selection (Standard V2, Low Resolution V2, CGI, etc.) - Output resolution options from 2K to 8K - Face enhancement feature - Real-time job tracking and status monitoring - Bulk download functionality - Dark mode toggle - Microsoft authentication integration - Comprehensive README with installation instructions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
72 lines
No EOL
2.4 KiB
PHP
72 lines
No EOL
2.4 KiB
PHP
<?php
|
|
include 'config.php';
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$debug = ["Received POST request"];
|
|
|
|
if (isset($_FILES['image'])) {
|
|
$image = $_FILES['image'];
|
|
$debug[] = "Image received: " . $image['name'];
|
|
} else {
|
|
$debug[] = "No image file received";
|
|
echo json_encode(['error' => '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']]);
|
|
} |