免费随机图片api接口

1、api接口整合

搏天:https://api.btstu.cn/
樱道:https://api.r10086.com/
樱花:https://www.dmoe.cc/
保罗:https://api.paugram.com/
EEE.DOG:https://api.yimian.xyz/
东方Project:https://img.paulzzh.tech/
likepoems随机图:https://api.likepoems.com/
Unsplash Image:https://source.unsplash.com/
缙哥哥博客: https://api.dujin.org/pic/yuanshen/
LoliAPI:https://www.loliapi.com/

2、api网站整合

2.1 搏天

网址:https://api.btstu.cn

  • 调用地址:https://api.btstu.cn/sjbz/api.php
    网站中有很多的接口,建议返回原站查询。

    搏天

2.2 樱道

网址:https://img.r10086.com

  • 调用地址:
    https://api.r10086.com/樱道随机图片api接口.php?自适应图片系列=原神
    网站中有很多的接口以及接口地址经常变更,建议返回原站查询。

    樱道

2.3 樱花

网址:https://www.dmoe.cc

  • 调用地址:
    https://www.dmoe.cc/random.php
    网站中有很多的接口,建议返回原站查询。

    在这里插入图片描述

2.4 保罗

网址:https://api.paugram.com

  • 调用地址:https://api.paugram.com/wallpaper/
    网站中有很多的接口,建议返回原站查询。

    保罗

2.5 EEE.DOG

网址:https://api.yimian.xyz

  • 调用地址:https://api.yimian.xyz/img/
    网站中有很多的接口,建议返回原站查询。

    EEE.DOG

2.6 东方Project

网址:https://img.paulzzh.tech

  • 调用地址:https://img.paulzzh.com/touhou/random
    网站中有很多的接口,建议返回原站查询。

    东方Project

2.7 likepoems随机图

网址:https://api.likepoems.com

  • 调用地址:
    二次元PC壁纸:https://api.likepoems.com/img/pc
    二次元PE壁纸:https://api.likepoems.com/img/pe
    mc酱壁纸:https://api.likepoems.com/img/mc
    pixiv壁纸:https://api.likepoems.com/img/pixiv
    nature壁纸:https://api.likepoems.com/img/nature
    必应壁纸:https://api.likepoems.com/img/bing

    likepoems

2.8 Unsplash Image

网址:https://source.unsplash.com/

  • 调用地址:https://source.unsplash.com/random

    Unsplash

2.9 缙哥哥博客

网址:https://api.dujin.org/pic/yuanshen/

  • 调用地址:https://api.dujin.org/pic/yuanshen/

    原神

2.10 LoliAPI

网址:https://www.loliapi.com/

  • 调用地址:https://www.loliapi.com/acg/
    网站中有很多的接口,建议返回原站查询。

    洛川唧

3、怎么自制随机图

3.1 普通的随机图

准备图片—>书写路径—>书写php文件
在img文件夹里新建img.txt,文件中直接写图片的URL地址,如:

https://static.likepoems.com/cdn/iro/logo.jpg

新建index.php文件。文件内容如下:

<?php
//存放api随机图链接的文件名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"));
}
?>

然后放在服务器里面的api文件夹里,绑定域名,记得开启php环境
访问路径:你的域名/api/img

3.2 通过sina图床搭建的随机图(可用)

index.php

<?php
//读取文本
$str = explode("\n", file_get_contents('img.txt'));
$k = rand(0,count($str));
$sina_img = str_re($str[$k]);
// 定义多个新浪图片请求接口
$size_arr = array('large', 'mw1024', 'mw690', 'bmiddle', 'small', 'thumb180', 'thumbnail', 'square');
$size = !empty($_GET['size']) ? $_GET['size'] : 'large' ;
$server = rand(1,4);
if(!in_array($size, $size_arr)){
    $size = 'large';
}
$daili_arr = array('i1.wp.com','cdn.cdnjson.com');
$daili = $daili_arr[array_rand($daili_arr,1)];

$url = 'https://'.$daili.'/tva'.$server.'.sinaimg.cn/'.$size.'/'.$url[$final_id].'.jpg';

//解析url
$result=array("code"=>"200","imgurl"=>"$url");
//定义type返回类型
$type=$_GET['return'];
switch ($type)
{
//Json格式解析
case 'json':
$imageInfo = getimagesize($url);
$result['width']="$imageInfo[0]";
$result['height']="$imageInfo[1]";
header('Content-type:text/json');
echo json_encode($result);
break;
//返回图片链接
default:
header("Location:".$result['imgurl']);
break;
}
function str_re($str){
  $str = str_replace(' ', "", $str);
  $str = str_replace("\n", "", $str);
  $str = str_replace("\t", "", $str);
  $str = str_replace("\r", "", $str);
  return $str;
}
?>

img.txt

007LvBV9gy1h4ogodv47cj31kw0w0791
007LvBV9gy1h4ogoe4j2uj31kw0w0dlo
007LvBV9gy1h4ogoecykvj31kw0w0439
007LvBV9gy1h4ogoen54nj31kw0w0ahk
007LvBV9gy1h4ogoexvlkj31kw0w00x1
007LvBV9gy1h4ogof8g3yj31kw0w0gpy
007LvBV9gy1h4ogofhtrhj31kw0w043g
007LvBV9gy1h4ogoftnewj31kw0w078y
007LvBV9gy1h4ogog3815j31kw0w00xa
007LvBV9gy1h4ogogebmfj31kw0w0n1q

和上面的一样,只是请求的是微博的图片。
请求示例:
你的域名/api/img?return=json 返回json格式
你的域名/api/img 返回普通图片

  • 26
    点赞
  • 138
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

likepoems

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值