自制随机图片api

作者: 会飞的鱼

全网最全的网络资源分享网站

手机扫码查看

特别声明:文章多为网络转载,资源使用一般不提供任何帮助,特殊资源除外,如有侵权请联系!

欢乐云计算

下面代码只适于新浪图片

<?php
//读取文本
$str = explode("\n", file_get_contents('wpimg.txt')); //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';
}
$url = 'https://tva'.$server.'.sinaimg.cn/'.$size.'/'.$sina_img.'.jpg';
//解析结果
$result=array("code"=>"200","imgurl"=>"$url");
 
//Type Choose参数代码
$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;
//IMG
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;
}
?>

然后在创建个txt文件 

txt文本里面的格式只取新浪外链图片的红色部分,一行一个

如:https://ws4.sinaimg.cn/large/65b17112ly1fv5ll42bsqj21hc0xc4b9.jpg

65b17112ly1fv5ll42bsqj21hc0xc4b9
65b17112ly1fv5ll4a2ktj21hc0xcqbi
65b17112ly1fv5ll4i3jnj21hc0xcwo3
65b17112ly1fv5ll4syu4j21hc0xcame
65b17112ly1fv5ll52zw7j21hc0xc7gz
65b17112ly1fv5ll5a4bwj21hc0xcak3
65b17112ly1fv5ll5imk2j21hc0xcn9o
65b17112ly1fv5ll5sc5wj21hc0xc14u
65b17112ly1fv5ll5zis3j21hc0xcgv9
65b17112ly1fv5ll67wiej21hc0xcwiu
65b17112ly1fv5lm7c4ksj21hc0xcgtw
65b17112ly1fv5lm7lfr9j21hc0xcdr2
65b17112ly1fv5lm7u9tsj21hc0xcqal
65b17112ly1fv5lm81p92j21hc0xck4s
65b17112ly1fv5lm8bb89j21hc0xck1x
65b17112ly1fv5lm8l94dj21hc0xck29
65b17112ly1fv5lm8ryeqj21hc0xcn6f
65b17112ly1fv5lm8zq87j21hc0xcwpj
65b17112ly1fv5lm98f8yj21hc0xcn7r
65b17112ly1fv5lm9rikgj21hc0xc7aq
65b17112ly1fv5lmv4gkhj21hc0xc111
65b17112ly1fv5lmvd7avj21hc0xc46t
65b17112ly1fv5lmvkny0j21hc0xcjxu
65b17112ly1fv5lmvrez9j21hc0xcai2
65b17112ly1fv5lmw0kqrj21hc0xck1i
65b17112ly1fv5lmw8j37j21hc0xc10r
65b17112ly1fv5lmwi1xzj21hc0xc0zh
65b17112ly1fv5lmwox42j21hc0xctk2
65b17112ly1fv5lmwzcqqj21hc0xc13i
65b17112ly1fv5lmx96v2j21hc0xcdr5
65b17112ly1fv5lmxkxwbj21hc0xcagl
65b17112ly1fv5lmxsnydj21hc0xc7b7
65b17112ly1fv5lmy5imtj21hc0xcgtl
65b17112ly1fv5lmyewwtj21hc0xcamh
65b17112ly1fv5lmyo0w7j21hc0xcwrz
65b17112ly1fv5lnpt8npj21hc0xcgrh
65b17112ly1fv5lnpz9avj21hc0xcdjh
65b17112ly1fv5lnq7vowj21hc0xcq8r
65b17112ly1fv5lnqh1f5j21hc0xcgv9
65b17112ly1fv5lnqr6u8j21hc0xcguj
65b17112ly1fv5lnqzat7j21hc0xcn4v
65b17112ly1fv5lnr69pjj21hc0xc7cr
65b17112ly1fv5lnrg8tzj21hc0xc46k
65b17112ly1fv5lnspfbvj21hc0xcdky
65b17112ly1fv5lnsxlizj21hc0xcdlu
65b17112ly1fv5lnt4yu2j21hc0xcwjb
65b17112ly1fv5lnteluij21hc0xck1e

本站接口地址:https://api.17uw.cn/api/bg/sinaimg.php

下面是图片示例,刷新一次随机显示一张

 

转载:http://duiai.cc/zi-zhi-sui-ji-tu-pian-api.html

分享到:
打赏
未经允许不得转载:

作者: 会飞的鱼, 转载或复制请以 超链接形式 并注明出处 会飞的鱼
原文地址: 《自制随机图片api》 发布于2019-6-11

评论

切换注册

登录

您也可以使用第三方帐号快捷登录

切换登录

注册

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏