Files
html/api/ambre-tool-image-upscale.php
2026-04-22 00:15:04 +02:00

32 lines
1.3 KiB
PHP

<?php
header("Content-Type: application/json; charset=utf-8");
$in = json_decode(file_get_contents("php://input"), true) ?: $_POST ?: $_GET;
$prompt = trim($in["prompt"] ?? $in["q"] ?? "");
if (!$prompt) { echo json_encode(["error"=>"prompt required"]); exit; }
$t0 = microtime(true);
$clean = preg_replace('/[^\p{L}\p{N}\s,.\-]/u', '', $prompt);
$clean = substr(trim($clean), 0, 300);
$seed = rand(1, 99999);
// HD size 2048x2048 for hi-res
$url = "https://image.pollinations.ai/prompt/" . urlencode($clean) . "?width=2048&height=2048&seed={$seed}&nologo=true&enhance=true&model=flux";
$ctx = stream_context_create(["http"=>["timeout"=>60]]);
$img = @file_get_contents($url, false, $ctx);
if (!$img || strlen($img) < 1000) { echo json_encode(["error"=>"upscale failed"]); exit; }
$dir = "/var/www/html/generated";
if (!is_dir($dir)) @mkdir($dir, 0755, true);
$slug = substr(preg_replace('/[^a-z0-9]+/', '-', strtolower($clean)), 0, 40);
$filename = "wevia-hd-{$slug}-" . date("Ymd-His") . "-" . bin2hex(random_bytes(3)) . ".png";
file_put_contents("$dir/$filename", $img);
echo json_encode([
"success"=>true, "prompt"=>$clean, "size"=>"2048x2048 HD",
"url"=>"https://weval-consulting.com/generated/$filename",
"size_kb"=>round(strlen($img)/1024, 1),
"elapsed_ms"=>round((microtime(true)-$t0)*1000),
"provider"=>"WEVIA Image HD",
]);