接入教程
1.访问php-noise.com获取API密钥
2.设置背景尺寸、主色调和噪点密度参数
3.调用生成接口获取PNG格式噪点背景图
4.可直接嵌入网页或下载本地使用
Python生成噪点背景图像
python
import requests
url = "https://php-noise.com/api/v1/generate"
params = {
"api_key": "YOUR_API_KEY",
"width": 800,
"height":追加 600,
"color": "#2c3e50",
"density": 0.3
}
response = requests.get(url, params=params)
if response.status_code == 200:
with open('noise_background.png', 'wb') as f:
f.write(response.content)
print("Image saved successfully")
else:
print(f"Error: {response.status_code}", response.text)
PHP调用噪点生成API
php
<?php
$url = "https://php-noise.com/api/v1/generate";
$params = [
'api_key' => 'YOUR_API_KEY',
'width' => 1200,
'height' => 800,
'color' => '#3498db',
'density' => 0.5
];
$query = http_build_query($params);
$full_url = $url . '?' . $query;
$image_data = file_get_contents($full_url);
if ($image_data !== false) {
file_put_contents('background.png', $image_data);
echo "Image generated successfully";
} else {
echo "Failed to generate image";
}
?>
JavaScript通过Fetch获取噪点图像
javascript
const apiKey = 'YOUR_API_KEY';
const url = new URL('https://php-noise.com/api/v1/generate');
url.searchParams.append('api_key', apiKey);
url.searchParams.append('width', 1024);
url.searchParams.append('height', 768);
url.searchParams.append('color', '#e74c3c');
url.searchParams.append('density', 0.7);
fetch(url)
.then(response => {
if (!response.ok) throw new Error('Network response was not ok');
return response.blob();
})
.then(blob => {
const imageUrl = URL.createObjectURL(blob);
const img = document.createElement('img');
img.src = imageUrl;
document.body.appendChild(img);
})
.catch(error => console.error('Error:', error));
常见问题
API调用需要付费吗?
PHP-Noise提供免费和付费套餐。免费套餐有调用次数限制,付费套餐提供更高调用限额和高级功能。具体套餐详情请访问官网。
生成的图像支持哪些格式?
API目前仅支持PNG格式输出。PNG格式支持透明背景,适合网页设计和UI界面使用。
如何获取API密钥?
访问PHP-Noise官网注册账号,在个人控制面板中可创建和管理API密钥。免费套餐用户可直接获取试用密钥。
Aitishiku.com