https://api.moelm.cn/api/random
https://api.moelm.cn/api/random/4K
https://api.moelm.cn/api/random/yln
https://api.moelm.cn/api/random/PC
服务器返回 302 跳转,浏览器直接加载图片。
可选 size 指定图片尺寸,0-7,数字越大尺寸越小,0=原图。
<img src="https://api.moelm.cn/api/random" alt="萌陌API">
<img src="https://api.moelm.cn/api/random?size=4" alt="指定尺寸">
添加 ?type=json 参数即可获得结构化数据,适合前端/后端程序对接。
{
"code": 200,
"url": "https://img.moelm.cn/i/2025/07/13/xxx.webp"
}
若传了 size 参数,响应中会额外包含 size / width 字段:
{
"code": 200,
"url": "https://img.moelm.cn/i/2025/07/13/xxx.webp",
"size": 3,
"width": 1920
}
// JavaScript fetch
fetch('https://api.moelm.cn/api/random?type=json')
.then(res => res.json())
.then(data => {
console.log(data.url); // 图片地址
// 设置到 img 标签
document.getElementById('myImg').src = data.url;
});
// JavaScript async/await
async function getRandomImage() {
const res = await fetch('https://api.moelm.cn/api/random?type=json');
const data = await res.json();
return data.url;
}
# PHP 调用
$json = file_get_contents('https://api.moelm.cn/api/random?type=json');
$data = json_decode($json, true);
echo $data['url']; // 图片地址
# Python 调用
import requests
data = requests.get('https://api.moelm.cn/api/random?type=json').json()
print(data['url']) # 图片地址