接入教程
1. 注册UpRes账户并获取API密钥
2. 参考文档准备待处理的图像文件
3. 选择需要的超分辨率模型(共18种)
4. 调用API接口提交处理请求
5. 接收返回的高清图像结果
6. 根据需求调整参数进行批量处理
Python调用示例:使用Real-ESRGAN模型放大图片
import requests
url = "https://api.upres.ai/v1/upscale"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
data = {
"image_url": "https://example.com/sample.jpg",
"model": "real-esrgan",
"scale": 4,
"output_format": "png"
}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
result = response.json()
print(f"Upscaled image available at: {result['url']}")
else:
print(f"Error: {response.status_code}", response.text)
PHP调用示例:批量处理多张图片
<?php
$apiUrl = "https://api.upres.ai/v1/batch";
$apiKey = "YOUR_API_KEY";
$data = [
"tasks" => [
[
"image_url" => "https://example.com/photo1.jpg",
"model" => "aurasr",
"scale" => 2
],
[
"image_url" => "https://example.com/photo2.jpg",
"model" => "seedvr2",
"scale" => .5
]
]
];
$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $apiKey",
"Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
JavaScript调用示例:前端直接上传图片
async function upscaleImage(file) {
const formData = new FormData();
formData.append('image', file);
formData.append('model', 'real-esrgan');
formData.append('scale', 4);
const response = await fetch('https://api.upres.ai/v1/upload', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
},
body: formData
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.json();
}
// Usage example
// const fileInput = document.getElementById('imageInput');
// upscaleImage(fileInput.files[0]).then(data => console.log(data));
常见问题
如何选择最适合的AI模型?
UpRes提供18种模型,Real-ESRGAN适合通用图像,SeedVR2擅长动漫/游戏画面,AuraSR优化真人照片。建议先测试不同模型在小样上的效果,或参考文档中的模型对比图表。
API支持哪些图片格式和最大尺寸?
支持JPEG、PNG、WebP输入,输出可选JPEG/PNG。输入图片最大20MB,分辨率上限4K。输出最高可达8K分辨率,具体取决于所选模型和缩放系数。
处理一张图片通常需要多长时间?
处理时间取决于图片大小、所选模型和缩放系数。通常4K图片放大2倍需10-30秒。API返回时包含预计时间,建议实现轮询或使用webhook接收异步结果。
Aitishiku.com