随机图片API

  • Post author:
  • Post category:其他




创建自己的图库



创建index.php和img.txt.

index.php写入以下代码:

<?php
//存有美图链接的文件名img.txt
$filename = "img.txt";
if(!file_exists($filename)){
    die('文件不存在');
}
 
//从文本获取链接
$pics = [];
$fs = fopen($filename, "r");
while(!feof($fs)){
    $line=trim(fgets($fs));
    if($line!=''){
        array_push($pics, $line);
    }
}
 
//从数组随机获取链接
$pic = $pics[array_rand($pics)];
 
//返回指定格式
$type=$_GET['type'];
switch($type){
 
//JSON返回
case 'json':
    header('Content-type:text/json');
    die(json_encode(['pic'=>$pic]));
 
default:
    die(header("Location: $pic"));
}
 
?>



img.txt写入图片链接,一行一个图片链接。

image-20201224135048141

创建

api.你的域名

网站并且设置域名解析。在网站根目录下创建文件夹。将上述两个文件放到刚创建的文件夹中。

如你的域名为abc.com,创建的网站为

api.abc.com

,创建的文件夹为pic。在浏览器中输入api.abc.com/acg/。即可随机显示img.txt中链接指向的图片。



可直接调用接口

如果你对API调用的图片并没有什么要求可以试试以下内容:



二次元随机图 – API


https://api.blogbig.cn/random/


来源:我爱浩瀚 https://www.blogbig.cn/



随机二次元接口源码-双版本

随机二次元接口源码-双版本

https://www.toubiec.cn/99.html

源码版权:苏晓晴



直接调用API

相关API接口Github上有开源:

https://github.com/Suxiaoqinx/acgimgurl


作者博客:晓晴博客

随机二次元图片接口-开放回归:

https://www.toubiec.cn/318.html

MORE:

15个随机图片API – zaxtyson

https://www.cnblogs.com/zaxtyson/p/11628746.html


随机图片获取api – 龙谷情Sinoam

https://www.cnblogs.com/lgqrlchinese/p/11386857.html

作者: 恐咖兵糖

本文首发于: 超光速

链接:

https://www.ftls.xyz/posts/38808/