小赖子的英国生活和资讯

如何在博客中随机的显示图片? 自制免费随机图片API

阅读 桌面完整版

自己弄的免费图床, 现在已经有5万多张图片了, 很多是由爬虫抓取的. 根据这里写的API文档, 你可以用以下的HTML代码显示一张随机的图片:

1
<img src='https://uploadbeta.com/api/pictures/random/' style='max-width:50%'>
<img src='https://uploadbeta.com/api/pictures/random/' style='max-width:50%'>

当然你也可以加入 参数 key, 比如只随机显示 BING 每日图纸:

1
<img src='https://uploadbeta.com/api/pictures/random/?key=BingEverydayWallpaperPicture' style='max-width:50%'>
<img src='https://uploadbeta.com/api/pictures/random/?key=BingEverydayWallpaperPicture' style='max-width:50%'>

效果如下:

你可以试着看看 Ctrl + F5 会不会更新, 也许不会, 这是因为用上了 CloudFlare缓存, 你可以点击以上的图片在新窗口打开然后再按Ctrl + F5 试试.

当然你不想每次刷新都更新的话可以用以下:

1
<img src='https://uploadbeta.com/api/pictures/random/?cached&key=BingEverydayWallpaperPicture' style='max-width:50%'>
<img src='https://uploadbeta.com/api/pictures/random/?cached&key=BingEverydayWallpaperPicture' style='max-width:50%'>

注意图片URL里加了 cached 参数, 这会告诉服务器每30分钟去更新一次随机图片.

比如 (NSFW) 显示随机美女图片可以用以下图片地址:

https://uploadbeta.com/api/pictures/random/?key=推女郎

相关说明文章

强烈推荐

微信公众号: 小赖子的英国生活和资讯 JustYYUK

阅读 桌面完整版
Exit mobile version