随机图片 API
返回一张随机图片。接口本身不返回图片内容,而是通过 302 Found 重定向到静态图片 URL。
请求
http
GET /random
GET /api/random两个地址行为相同。
参数
| 参数 | 可选值 | 默认值 | 说明 |
|---|---|---|---|
t | origin、webp | origin | 返回原图或 WebP 图片 |
o | l、h、p、v | 随机 | l / h 表示横向,p / v 表示竖向 |
参数以查询字符串形式传入,例如 /random?t=webp&o=l。
示例
获取任意原图
bash
curl -I https://your-domain.example/random获取 WebP 横向图片
bash
curl -I "https://your-domain.example/random?t=webp&o=l"在网页中使用
html
<img src="https://your-domain.example/random?t=webp&o=p" alt="随机壁纸" />响应
成功时返回 302 Found,Location 响应头指向对应的静态图片:
http
HTTP/1.1 302 Found
Location: /webp/portrait/example.webp当对应类型或方向没有可用图片时,返回 404:
json
{
"error": "No images found"
}静态图片 URL
如果需要固定图片,可以直接使用以下路径:
text
/origin/landscape/<文件名>
/origin/portrait/<文件名>
/webp/landscape/<文件名>
/webp/portrait/<文件名>静态图片会使用长期缓存,更新图片后应使用新的文件名或路径。